AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

L1-8 现代战争

作者: 作者的头像   WindSkyEnd ,  2025-05-09 17:27:00 · 山东 ,  所有人可见 ,  阅读 4


0


难度不大,但是需要熟练使用结构体以及结构体重载符号排序

#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;
    }
}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息