COdeforces Round #264 (Div. 2) C. Gargari and Bishops
2014-08-31 00:31
507 查看
直接暴力枚举,分别枚举黑白棋盘中最大的,二者相加即可。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 2005;
int grid[maxn][maxn];
ll a[maxn<<1],b[maxn<<1];
int n;
int main(){
while(~scanf("%d",&n)){
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++){
scanf("%d",&grid[i][j]);
a[i+j] += (ll)grid[i][j];
b[i+n-j] += (ll)grid[i][j];
}
int x1 = 0,y1 =0;
ll temp1 = -1;
int jj;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j += 2){
if(i&1)
jj = j+1;
else
jj = j;
ll temp = a[i+jj] + b[i+n-jj] - (ll)grid[i][jj];
if(temp1 < temp){
x1 = i;
y1 = jj;
temp1 = temp;
}
}
}
int x2 = 0,y2 = 0;
ll temp2 = -1;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j += 2){
if(i&1)
jj = j;
else
jj = j+1;
ll temp = temp = a[i+jj] + b[i+n-jj] - (ll)grid[i][jj];;
if(temp2 < temp){
x2 = i;
y2 = jj;
temp2 = temp;
}
}
}
printf("%I64d\n%d %d %d %d\n",temp1+temp2,x1,y1,x2,y2);
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 2005;
int grid[maxn][maxn];
ll a[maxn<<1],b[maxn<<1];
int n;
int main(){
while(~scanf("%d",&n)){
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++){
scanf("%d",&grid[i][j]);
a[i+j] += (ll)grid[i][j];
b[i+n-j] += (ll)grid[i][j];
}
int x1 = 0,y1 =0;
ll temp1 = -1;
int jj;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j += 2){
if(i&1)
jj = j+1;
else
jj = j;
ll temp = a[i+jj] + b[i+n-jj] - (ll)grid[i][jj];
if(temp1 < temp){
x1 = i;
y1 = jj;
temp1 = temp;
}
}
}
int x2 = 0,y2 = 0;
ll temp2 = -1;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j += 2){
if(i&1)
jj = j;
else
jj = j+1;
ll temp = temp = a[i+jj] + b[i+n-jj] - (ll)grid[i][jj];;
if(temp2 < temp){
x2 = i;
y2 = jj;
temp2 = temp;
}
}
}
printf("%I64d\n%d %d %d %d\n",temp1+temp2,x1,y1,x2,y2);
}
return 0;
}
相关文章推荐
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
- Codeforces Round 264(div2) C. Gargari and Bishops
- Codeforces #264 (Div. 2) D. Gargari and Permutations
- Codeforces #264 (Div. 2) D. Gargari and Permutations
- Codeforces Round #264 (Div. 2)-B. Caisa and Pylons
- Codeforces Round #264 (div2)B. Caisa and Pylons
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp
- Codeforces Round #416 (Div. 2) C - Vladik and Memorable Trip
- Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟
- Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)
- Codeforces Round #174 (Div. 2) B. Cows and Poker Game(简单)
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
- 【Codeforces Round 370 (Div 2) B】【简单贪心】Memory and Trident
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence(构造,思路)
- Codeforces Round #269 (Div. 2) B. MUH and Important Things
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分
- 【Codeforces Round 169 (Div 2) E】【数据结构区间维护】Little Girl and Problem on Trees 大菊花树的距离性修改查询
- Codeforces Round #404 (Div. 2) -- C. Anton and Fairy Tale(二分)