lp2356
https://www.luogu.org/problemnew/show/P2356
一维数组解决二维题目,妙啊
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 int x[10005]={0},y[10005]={0},n,m,count = 0; 5 //x,y 是每个"容身之地"的坐标,count为其个数 6 int flag = 0;// 记录有没有"容身之地" 7 int maxn = -1; 8 int main(){ 9 int hang[1005]={0},lie[1005]={0}; 10 //保存每行每列的和 11 cin >> n; 12 for(int i = 1;i <= n;i++){ 13 for(int j = 1;j <= n;j++){ 14 scanf("%d",&m); 15 hang[i] += m; 16 lie[j] += m; //把值加上去 17 if(m == 0){ //有"容身之地" 18 count++;//"容身之地"个数加一 19 x[count] = i; 20 y[count] = j; //保存x y 21 flag = 1; 22 } 23 } 24 } 25 if(flag == 0) printf("Bad Game!\n");//没有"容身之地" 26 if(flag == 1){ 27 for(int i = 1;i <= count;i++){ 28 if(hang[x[i]] + lie[y[i]] > maxn) 29 maxn = hang[x[i]] + lie[y[i]]; //计算每个没有"容身之地"的行列之和 30 } 31 cout << maxn << endl; 32 } 33 return 0; 34 }