题目:

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. python开源包提交到pypi社区

    为啥要提交到pypi?因为提交成功后,你今后想用你自己写的模块,只要pip install一下就可以了. 那么如何提交?请参看本篇教程 首先要确定你的包叫啥名,比如我的包叫xlutils3,既然确定了 ...

  2. Google搜索的常用技巧

    个人搜索方案 1.选择合适的搜索词,一些行业术语或专家名字可以带来更加高质量的结果. 2.搜索词手动使用空格分隔,先进行第一次搜索,看搜索结果标题是否满足预期,如果不满足,采用更换关键词,添加关键词, ...

  3. 搞JAVA在北京月薪15K的朋友来到厦门却很难找到工作

    朋友是搞JAVA开发的,从北京来.来前朋友们都感觉他在厦门应该很快就能找到工作,因为厦门的IT人员很缺. 没想到来厦门大概半个多月了,到现在都还没着落.面试单位每周基本只有两家,而且面试的感觉都说不错 ...

  4. Linux 下C++编写

    今天搞了一天Linux下C++编程,还没有什么成效.好烦躁好心焦,想砸电脑的冲动.抽根烟理下思路一定要把它拿下!! ===搞了两天,真是搞到生无可恋,试了共享文件, 试了网络配置,各种博客就是各种行不 ...

  5. asp.net mvc下ckeditor使用

    资源下载:ckeditor 第一步,引入必须文件“~/ckeditor/ckeditor.js” 第二步,替换文本域 <%: Html.TextArea("Content", ...

  6. 第二百一十七天 how can I 坚持

    JavaScript  document.getElementByName()获取数组,for循环,搞了一天,好笨. 明天要下雪了,好冷. 双十一,天猫搞的挺特别啊,晚上抢了个小米红包,不知道买啥,哎 ...

  7. Linux下的设置静态IP命令详解

    网络配置的配置文件在/etc/sysconfig/network-scripts/下,文件名前缀为ifcfg-后面跟的就是网卡的名称,可以通过双TAB键查看然后编辑,也可以使用ifconfig查看,也 ...

  8. C++11右值引用

    [C++11右值引用] 1.什么是左值?什么是右值? 左值是表达式结束后依然存在的对象:右值是表达式结束时就不再存在的对象. 2.std::move的作用是什么? std::move用于把任意类型转化 ...

  9. spring mvc中的valid

    当你希望在spring mvc中直接校验表单参数时,你可以采用如下操作: 声明Validator的方式: 1.为每一个Controller声明一个Validator @Controller publi ...

  10. 进入GRUB改root用户密码

    开机读取倒计时时按任意键----e---->选择第二行 kernel ---->按e, 再按空格 >输入1----回车--->选择kernel输入b----> passw ...