这个题, 最主要的应该是找到对角线上的格子的关系。 “ " 这种对角线, 关系是x-y+n相等, ” / “ 这种, 关系是x+y相等。知道每个格子的两种对角线的值, 那么这个格子的值可以表示为d1[x+y]+d2[x-y+n]-a[x][y], a[x][y]是初值。 知道这个以后就好做了。
具体可以看这里http://blog.csdn.net/kenden23/article/details/38959141.....
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define pb(x) push_back(x) 4 #define ll long long 5 #define mk(x, y) make_pair(x, y) 6 #define lson l, m, rt<<1 7 #define mem(a) memset(a, 0, sizeof(a)) 8 #define rson m+1, r, rt<<1|1 9 #define mem1(a) memset(a, -1, sizeof(a)) 10 #define mem2(a) memset(a, 0x3f, sizeof(a)) 11 #define rep(i, a, n) for(int i = a; i<n; i++) 12 #define ull unsigned long long 13 typedef pair<int, int> pll; 14 const double PI = acos(-1.0); 15 const double eps = 1e-8; 16 const int mod = 1e9+7; 17 const int inf = 1061109567; 18 const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; 19 ll a[2005][2005], d1[5000], d2[5000]; 20 int ans[3][2]; 21 int main() 22 { 23 int n; 24 cin>>n; 25 for(int i = 0; i<n; i++) { 26 for(int j = 0; j<n; j++) { 27 scanf("%d", &a[i][j]); 28 d1[i+j] += a[i][j]; 29 d2[i-j+n] += a[i][j]; 30 } 31 } 32 for(int i = 0; i<n; i++) { 33 for(int j = 0; j<n; j++) { 34 a[i][j] = d1[i+j]+d2[i-j+n]-a[i][j]; 35 } 36 } 37 ans[1][0] = ans[1][1] = ans[2][0] = 0; 38 ans[2][1] = 1; 39 for(int i = 0; i<n; i++) { 40 for(int j = 0; j<n; j++) { 41 if((i+j)&1) { 42 if(a[i][j]>a[ans[1][0]][ans[1][1]]) { 43 ans[1][0] = i; 44 ans[1][1] = j; 45 } 46 } else { 47 if(a[i][j]>a[ans[2][0]][ans[2][1]]) { 48 ans[2][0] = i; 49 ans[2][1] = j; 50 } 51 } 52 } 53 } 54 cout<<a[ans[1][0]][ans[1][1]]+a[ans[2][0]][ans[2][1]]<<endl; 55 cout<<ans[1][0]+1<<" "<<ans[1][1]+1<<" "<<ans[2][0]+1<<" "<<ans[2][1]+1<<endl; 56 }