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. iOS push新的调用方法

    // IOS8 新系统需要使用新的代码if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){    [[UIAppl ...

  2. VirtualBox安装android-x86-4.4-r2

    https://jingyan.baidu.com/album/a681b0de1373133b184346cf.html?picindex=10

  3. 几个H5炫酷特效

    那H5里有哪些高级动效了?小编仔细体验了国内不少几个优秀H5页面作品,整理出下面几个H5页面特效.我们的H5作品如果能用上其中一两个,相信能增色不少! 1.粒子特效 —>>一键爆炸 模拟现 ...

  4. Hotspot参数分析

    -XX:+HeapDumpOnOutOfMemoryError 让虚拟机在出现内存溢出异常时Dump出当前的内存堆转储快照以便事后进行分析 -Xmx与-Xms 虚拟机堆参数 -Xoss 设置本地方法栈 ...

  5. mysqli_query数据库有数据,查不出来

    MySQLDB.class.php <?php /** * 数据库操作工具类 */ class MySQLDB { // 定义相关属性 private $host;// 主机地址 private ...

  6. vue动态路由配置,vue路由传参

    动态路由: 当我们很多个页面或者组件都要被很多次重复利用的时候,我们的路由都指向同一个组件,这时候从不同组件进入一个"共用"的组件,并且还要传参数,渲染不同的数据 这就要用到动态路 ...

  7. .NET发送邮件的方法

    整理一下,在.NET中发送邮件的一个方法,代码如下: public static string Net_Email(string strSendto, string strCC, string str ...

  8. python程序保存成二进制(不公开源码)

    https://www.tiobe.com/ (python语言排行榜) pip install pyinstaller pyinstaller test.py ./test

  9. 【RabbitMQ】 RabbitMQ配置开机启动

    环境 系统:Linux(CentOS 7.2) Erlang环境:21.1(安装参考[Erlang]源码安装) RabbitMQ:3.7.9(安装参考[RabbitMQ] RabbitMQ安装) 配置 ...

  10. LD_LIBRARY_PATH

    LD_LIBRARY_PATH是Linux环境变量名,该环境变量主要用于指定查找共享库(动态链接库)时除了默认路径之外的其他路径. 在linux下可以用export命令来设置这个值,比如 在linux ...