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. windows2003两台服务器,局域网之间不能互相访问

    准备在两台服务器之间,映射网络驱动器,但怎么也连不上了. 可以在网络邻居中看到对方的机器,但就是访问不到共享的文件,也无法做网络映射. 搜索了一下,发现在是因为防火墙中,没有把"文件和打印机 ...

  2. sqlserver 2008 还原数据库时,提示有用户正在使用,无法取得使用占有权

    sqlserver 2008 还原数据库时,提示有用户正在使用,无法取得使用占有权 这个时候,只需要把数据库分离出去,再附加,然后还原即可 分离数据库的时候能看到有几个数据连接

  3. JTable 查询

    public JTable query(String table) throws SQLException { DefaultTableModel tablemodel = new DefaultTa ...

  4. 20岁的设计师vs30岁的设计师

    20岁的设计师vs30岁的设计师 如果你还是20来岁,要恭喜你,你还年轻, 一切才刚刚开始 还有时间去探索无尽的可能 还有时间去找到无限的前途 ​ 如果30岁的你还不够强大, 请记得时刻给予自己信心, ...

  5. msdn

    https://docs.microsoft.com/en-us/cpp/standard-library/basic-string-class?view=vs-2017

  6. python 的文件操作

    二进制用法 f=open('test.txt','wb') f.write("汉字\r\n".encode('UTF-8')) f.write("hello". ...

  7. android 使用UDP发送数据 DatagramSocket 创建对象为null

    DatagramSocket socket=null; try { socket = new DatagramSocket();  //这里创建对象为空 } catch (SocketExceptio ...

  8. GOIP connects with Elastix through “config by line”

    GOIP connects with Elastix through “config by line” By grace Liu on May 17, 2013 in Elastix, Gateway ...

  9. Python开课复习-10/16

    import random # random 随机数模块 # print(random.random()) #----float 大于0且小于1之间的小数# print(random.choice([ ...

  10. linux vi操作

    1.“i”键,进入编辑状态.可以看到命令的下方出现了“--INSERT--”字样,表示成功进入了编辑模式; 2.“Esc”键,退出编辑模式.并在此时输入“:wq”以退出并保存