5 solutions

  • 5
    @ 2025-4-26 19:52:53

    #include<bits/stdc++.h> using namespace std; int n, m, k; int a[1005][1005]; bool r[1005], c[1005]; // 分别记录行和列是否被轰炸

    struct node{ int val,x,y; }e[1000005];

    bool cmp(node a,node b) { return a.val > b.val; } int main() { cin >> n >> m >> k; int cnt = 0; for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= m ; j++) { cin >> a[i][j]; e[++cnt] = {a[i][j],i,j}; } } queue<pair<int,int> >q; sort(e+1,e+1+cnt,cmp); //cout<<cnt<<endl; for(int i = 1 ; i <= cnt ; i ++) { q.push({e[i].x,e[i].y}); } int sum = 0; while(!q.empty()) { int u = q.front().first; int v = q.front().second; q.pop(); if(r[u] || c[v]) continue; if(sum == k) break; sum++;

    	r[u] = 1;
    	c[v] = 1;
    }
    for(int i = 1 ; i <= n ; i++)
    {
    	if(r[i]) continue;
    	for(int j = 1 ; j <= m ; j++ )
    	{
    		if(!c[j])
    		{
    			cout<<a[i][j]<<" ";
    		}
    	}
    	cout<<endl;
    }
    
    return 0;
    

    }

    Information

    ID
    1327
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    (None)
    # Submissions
    124
    Accepted
    42
    Uploaded By