http://codeforces.com/contest/463/problem/C

在一个n∗n的国际象棋的棋盘上放两个主教,要求不能有位置同时被两个主教攻击到,然后被一个主教攻击到的位置上获得得分。求得分的最大值。

黑白格分开考虑最大值即可,注意全0情况。

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
int n;
const int maxn = 2500;
LL s[maxn][maxn];
LL sum[maxn*2],cha[maxn*2];
struct node{
LL fen;
int x,y;
}a[maxn*maxn/2],b[maxn*maxn/2];
int main()
{
RD(n);
clr0(sum),clr0(cha);
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j){
scanf("%I64d",&s[i][j]);
sum[i+j] += s[i][j];
cha[j-i+maxn] += s[i][j];
}
int cnt_a = 0,cnt_b = 0;
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j){
LL fen = sum[i+j] + cha[j-i+maxn] - s[i][j];
if((i+j)&1){
a[cnt_a++] = (node){fen,i,j};
}
else{
b[cnt_b++] = (node){fen,i,j};
}
}
LL ans_a = -1,ans_b = -1;
int x1,y1,x2,y2;
for(int i = 0;i < cnt_a;++i){
if(ans_a < a[i].fen){
ans_a = a[i].fen;
x1 = a[i].x,y1 = a[i].y;
}
}
for(int i = 0;i < cnt_b;++i){
if(ans_b < b[i].fen){
ans_b = b[i].fen;
x2 = b[i].x,y2 = b[i].y;
}
}
printf("%I64d\n",ans_a+ans_b);
printf("%d %d %d %d\n",x1,y1,x2,y2);
return 0;
}

Codeforces Round #264 (Div. 2) C. Gargari and Bishops 主教攻击的更多相关文章

  1. Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】

    称号: 意甲冠军:给定一个矩阵,每格我们有一个数,然后把两个大象,我希望能够吃的对角线上的所有数字.我问两个最大的大象可以吃值. 分析:这种想法是暴力的主题,计算出每一格放象的话能得到多少钱,然后求出 ...

  2. Codeforces Round #264 (Div. 2) D. Gargari and Permutations 多序列LIS+dp好题

    http://codeforces.com/contest/463/problem/D 求k个序列的最长公共子序列. k<=5 肯定 不能直接LCS 网上题解全是图论解法...我就来个dp的解法 ...

  3. Codeforces Round #264 (Div. 2) C

    题目: C. Gargari and Bishops time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  4. Codeforces Round #264 (Div. 2)

    http://codeforces.com/contest/463 这场是我人生第一场cf啊.. 悲剧处处是啊. 首先,看不懂题,完全理解不了啊.都是wa了好几次才过的 所以a和b这两sb题我做了1个 ...

  5. Codeforces Round #264 (Div. 2) E. Caisa and Tree 树上操作暴力

    http://codeforces.com/contest/463/problem/E 给出一个总节点数量为n的树,每个节点有权值,进行q次操作,每次操作有两种选项: 1. 询问节点v到root之间的 ...

  6. Codeforces Round #264 (Div. 2) D

    题意: 给出最多5个序列,问这几个序列的最长公共子序列的长度是多少. solution : 脑抽级别我是,第一个序列每个数字位置固定,这样只要维护一个k-1维的偏序集就好了.然后在保证每个位置合法的情 ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. css font-size=0的妙用

    转自:css font-size=0有什么妙用? 回答一: 问题的根源是 inline(a标签默认是display:inline) 和 inline-block (.list-info 设置的是 di ...

  2. PHP swoole process的使用

    引入背景:假如我们每天有10000个订单生成,需要同步到仓储系统中去,以前做法是开启一个crontab去跑这些任务,但是发现总有感觉同步效率低,间隔时间都是分钟级别的. 解决方案测试:我们将同步订单的 ...

  3. Get、Post 提交的乱码问题

    1.问题 在spring mvc开发的时候出现乱码问题: 2.解决方案 (1)Get提交:tomcat容器接收的造成的乱码问题,修改server.xml文件: (2)Post提交:在web.xml中配 ...

  4. linux RCU锁机制分析

    openVswitch(OVS)源代码之linux RCU锁机制分析 分类: linux内核  |  标签: 云计算,openVswitch,linux内核,RCU锁机制  |  作者: yuzhih ...

  5. iOS.Debug.Simulator

    1. iOS Simulator Tips & Tricks http://code.tutsplus.com/tutorials/ios-simulator-tips-tricks--mob ...

  6. BZOJ1226或洛谷2157 [SDOI2009]学校食堂

    BZOJ原题链接 洛谷原题链接 注意到\(B[i]\)很小,考虑状压\(DP\). 设\(f[i][j][k]\)表示前\(i - 1\)个人已经拿到菜,第\(i\)个人及其后面\(7\)个人是否拿到 ...

  7. centos7 搭建vnc服务

  8. Codeforces 749C. Voting 模拟题

    C. Voting time limit per test: 1 second memory limit per test: 256 megabytes input: standard input o ...

  9. divinglaravel.com

    https://divinglaravel.com/ 这是一个深入 laravel 的学习网站

  10. c++11 stl 学习之 shared_ptr

    shared_ptr智能指针 shared_ptr 的声明初始化方式由于指针指针使用explicit参数 必须显示声明初始化shared_ptr<string> pNico = new s ...