COdeforces Round #264 (Div. 2) C. Gargari and Bishops

直接暴力枚举,分别枚举黑白棋盘中最大的,二者相加即可。

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值