1/* 2 Question: Give you an N * n grid. Each grid has a value! Put two bishops on a grid. 3. Each Bishop can attack the grid on the diagonal line (the diagonal line of the main line and the diagonal line of the person ), then the four values on the grid are obtained (only once ). The maximum values obtained by two bishops and their locations must be output! 5 6 7 ideas: direct violence !.... Good brute force questions! 8 first, we all know that the horizontal and vertical coordinates on each primary diagonal line are the same and the differences between the horizontal and vertical coordinates on each diagonal line are the same! 9. Then, we can sum up the values on all diagonal lines during input! At the end of, we found that if we want to obtain the maximum value, there will be another one that the diagonal lines of two bishops cannot overlap on the same grid of 12! As long as the sum of the two bishops ordinate values is equal to or even to each other! 13 14 in all the grids, find the sum of X and Y coordinates and obtain 15 of the largest and Y coordinates on the diagonal line and an even number and obtain the largest number of grids on the diagonal line! 16 The sum of the maximum obtained values is the final answer! 17 */18 # include <iostream> 19 # include <cstring> 20 # include <cstdio> 21 # include <algorithm> 22 # define n 200523 using namespace STD; 24 typedef long ll; 25 int num [N] [N]; 26 ll sumn [N * 2], Summ [N * 2]; 27 28 int N; 29 30 int main () {31 While (scanf ("% d", & N )! = EOF) {32 memset (sumn, 0, sizeof (sumn); 33 memset (Summ, 0, sizeof (summ); 34 for (INT I = 1; I <= N; ++ I) 35 for (Int J = 1; j <= N; ++ J) {36 scanf ("% d ", & num [I] [J]); 37 sumn [I + J] + = num [I] [J]; // The sum of X and Y coordinates is the diagonal value of I + J and 38 summ [I-j + N] + = num [I] [J]; // The vertical and horizontal coordinates are the diagonal values of I-j and 39} 40 41 LL maxodd =-1, maxevent =-1, s; 42 int x1, x2, Y1, y2; 43 for (INT I = 1; I <= N; ++ I) 44 for (Int J = 1; j <= N; ++ J) {45 if (I + J) & 1) {46 If (maxodd <(S = sumn [I + J] + summ [I-j + N]-num [I] [J]) {47 maxodd = s; // The sum of X and Y coordinates is an odd number and the maximum number of grids on the diagonal line is obtained 48x1 = I; 49 Y1 = J; 50} 51} 52 else {53 If (maxevent <(S = sumn [I + J] + summ [I-j + N]-num [I] [J]) {54 maxevent = s; // The sum of X and Y coordinates is an even number, and the maximum number of grids on the diagonal line is obtained. 55x2 = I; 56 y2 = J; 57} 58} 59} 60 61 printf ("% LLD \ n", maxodd + maxevent); 62 printf ("% d \ n", X1, y1, X2, Y2); 63} 64 return 0; 65}
Codeforces gargari and Bishops (good brute force)