L1-8 现代战争
作者:
WindSkyEnd
,
2025-05-09 17:27:00
· 山东
,
所有人可见
,
阅读 4
难度不大,但是需要熟练使用结构体以及结构体重载符号排序
#include <bits/stdc++.h>
#define debug(x) cout << '!' << (x) << '!' << endl
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int n , m , k;
const int N = 1010;
ll g[N][N];
bool stc[N] , str[N];//判断行列是否被炸掉了
struct Rec{
ll w;
int r;
int c;
bool operator <(const Rec &W)const{
return w < W.w;
}
}rec[N*N];
int cnt = 0;
int main(){
cin >> n >> m >> k;
for(int i = 0 ;i < n ; i++){
for(int j = 0 ; j < m ; j++){
cin >> g[i][j];
rec[cnt++] = {g[i][j],i,j};
}
}
// for(int i = 0 ; i < n ; i++){
// for(int j = 0 ; j < m ; j++)cout << g[i][j]<<' ';
// cout << endl;
// }
//重置排序
sort(rec,rec+cnt);
int ccnt = 0;
for(int i = cnt-1 ; i >= 0 && ccnt < k ; i--){
int c = rec[i].c , r = rec[i].r;
if(!stc[c] && !str[r]){
stc[c] = str[r] = true;
ccnt ++;
}
}
for(int i = 0 ; i < n ; i++){
if(str[i]) continue;
bool diyige = false;
for(int j = 0 ; j < m ; j++){
if(stc[j]) continue;
if(diyige) cout << ' ';
cout << g[i][j];
diyige = true;
}
cout << endl;
}
}