题目:

C. Gargari and Bishops
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.

He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such
a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops
Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.

We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).

Input

The first line contains a single integer n (2 ≤ n ≤ 2000).
Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) —
description of the chessboard.

Output

On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n),
where xi is
the number of the row where the i-th bishop should be placed, yi is
the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from
top to bottom, and columns are numbered from 1 to n from left to right.

If there are several optimal solutions, you can print any of them.

Sample test(s)
input
4
1 1 1 1
2 1 1 0
1 1 1 0
1 0 0 1
output
12
2 2 3 2

题意分析:


给你一个n*n的格子,每个格子都有一个数值!将两仅仅bishops放在某一个格子上,每个bishop能够攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的数值(仅仅能获取一次)。要求输出两个bishops获取的最大值以及它们所在的位置!

思路:暴力吧,首先我们都知道每一条主对角线上的横纵坐标的和同样,每一条副对角线上的横纵坐标的差同样!那么我们在输入的时候就能够将全部对角线上的数值之和求出来了。 最后我们发现假设要获得最大值,那么另一条就是两个bishops所在的对角线不能相交在同一个格子上。仅仅要满足两个bishops的哼纵坐标之和互为奇偶即可了。在全部格子中找到横纵坐标之和为奇数而且获得对角线上数值最大的格子和横纵坐标之和为偶数而且获得对角线上数值最大的格子。二者最大获得值相加就是终于的答案了。 比赛没什么好的思路,如今补上。非常不错的题目

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 2005
using namespace std;
typedef long long LL;
int num[N][N];
LL sumN[N*2], sumM[N*2]; int n; int main()
{
while(scanf("%d", &n)!=EOF)
{
memset(sumN, 0, sizeof(sumN));
memset(sumM, 0, sizeof(sumM));
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
{
scanf("%d", &num[i][j]);
sumN[i+j]+=num[i][j];//横纵坐标之和为i+j的对角线的数值和
sumM[i-j+n]+=num[i][j];//横纵坐标之差为i-j的对角线的数值和
} LL max1=-1, max2=-1, s;
int x1, x2, y1, y2;
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
{
if((i+j)&1)
{
if(max1<(s=sumN[i+j]+sumM[i-j+n]-num[i][j]))
{
max1=s;//横纵坐标之和为奇数而且获得对角线上数值最大的格子
x1=i;
y1=j;
}
}
else
{
if(max2<(s=sumN[i+j]+sumM[i-j+n]-num[i][j]))
{
max2=s;//横纵坐标之和为偶数而且获得对角线上数值最大的格子
x2=i;
y2=j;
}
}
} printf("%lld\n",max1+max2);
printf("%d %d %d %d\n", x1, y1, x2, y2);
}
return 0;
}

Codeforces Round #264 (Div. 2) C的更多相关文章

  1. Codeforces Round #264 (Div. 2)

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

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

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

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

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

  4. Codeforces Round #264 (Div. 2) C. Gargari and Bishops 主教攻击

    http://codeforces.com/contest/463/problem/C 在一个n∗n的国际象棋的棋盘上放两个主教,要求不能有位置同时被两个主教攻击到,然后被一个主教攻击到的位置上获得得 ...

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

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

  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. qq互联登陆开发流程

    宋正河整理 百度文库在线观看: http://wenku.baidu.com/view/96da9744e518964bcf847c47.html?st=1 csdn免积分下载: http://dow ...

  2. php 采集程序 宋正河

    本程序主要是通过php采集网页信息,程序自动存储采集进度,采用phpquery简化元素节点匹配,采集到的内容直接入库 你要做的只是写好采集语法,本程序适合有一定php基础的人使用!当然你也可以进行修改 ...

  3. PHP中mysql_affected_rows()和mysql_num_rows()区别

    mysql_affected_rows -- 取得前一次 MySQL 操作所影响的记录行数mysql_num_rows -- 函数返回结果集中行的数目. config.php <?php hea ...

  4. 分享一些前端chm文档

    分享地址:http://yun.baidu.com/share/link?shareid=39230983&uk=1008683945 对于网络不好的人来说,离线文档更加方便.打开速度更快. ...

  5. 通过xshell 设置代理上网

    前言: 前段时间,选修了一门并行计算,老师给我们每个人分配了一个linux登录账号,通过这个账号,可能登录学校的一台linux . 一次偶然的机会,了解到可以通过xshell , ssh服务器给本地开 ...

  6. PHP上传大文件和处理大数据

    1. 上传大文件 /* 以1.5M/秒的速度写入文件,防止一次过写入文件过大导致服务器出错(chy/20150327) */ $is_large_file = false; if( strlen($x ...

  7. centos 7搭建vpn(pptpd)服务器 (只限centos 7)

    第一步:首先检查ppp是否开启  若使用XEN构架的VPS,此步骤不用执行 终端输入命令:cat /dev/ppp 开启成功的标志:No such file or directory 或者 No su ...

  8. javascript压缩图片无刷新上传

    首先要说明,该方式我没有实现成功,主要问题点是压缩后能拿到压缩后图片地址,确不知道怎么上传上去,如果有哪位大牛可以指点一二,万分感谢. 图片压缩代码: compress: function(sourc ...

  9. 实体框架 (EF) 入门 => 三、CodeFirst 支持的完整特性列表

    KeyAttribute 设置主键.如果为int类型,将自动设置为自增长列. 系统默认以Id或类名+Id作为主键.StringLengthAttribute 可设置最大最小长度以及验证提示信息等.最大 ...

  10. KextWizard 的使用方法;以及Kext安装的几种工具下载

    a.将你需要安装的Kext拖到非中文的路径中: b.运行该软件,将Kext拖入下图对应的方框里,然后选择位置安装: c.选择修复权限和重建缓存(一个是修复Extra文件夹,一个是修复SLE) Kext ...