题目:

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. 横版动作MOBA《超宇宙》首测试玩曝光 详解游戏特色(转)

    http://play.163.com/15/0911/11/B37RHHO100314J6L.html

  3. Floyd算法解决最短路径问题

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 万圣节的中午,A和B在吃过中饭之后,来到了一个新的鬼屋!鬼屋中一共有N个地点,分别编号为1..N,这N个地点之间互相有一些 ...

  4. spring初探1

    spring初探1 关于新建对象,对象依赖的三种方式比较 场景 某个交易的业务组建拆分,为原先的功能模块新写了一个业务组件 使用new. 修改上层代码的对象生成部分( 如果不是面向接口编程,简直就是灾 ...

  5. MarkdownPad 破解学习

    最近学习 Markdown,从网上下载了 Windows 下的编辑器:MarkdownPad.这款软件分为免费版和专业版(收费), 对于普通用户来说免费版已经足够,专业版比免费版多了如下几个功能: 一 ...

  6. 黑马程序员——有关protocol的小结

    在OC程序中经常会有这样的问题就是一个类想让其他类帮自己实现某些方法,然后再将结果返回给这个类:如何让一个类要找的代理去实现自己想要的方法呢? 这样就需要有一个协议,让能遵守协议的其他类都能实现协议中 ...

  7. TopFreeTheme精选免费模板【20130629】

    今天给大家推荐9款最新精选的WordPress主题,它们涵盖了新闻.杂志.博客.房地产方面的主题.有些是商业模板,但现在都可以免费下载. GeoPlaces v4.6.2 – 来自Templatic的 ...

  8. Hadoop学习记录(7)|Eclipse远程调试Hadoop

    1.创建Hadoop项目 2.创建包.类 这里使用hdfs.WordCount为例 3.编写自定Mapper和Reducer程序 MyMapper类 static class MyMapper ext ...

  9. php 扩展apc 参数优化

    编辑php.ini 输入下面 [apc] apc.enabled=1apc.shm_segments = 1apc.shm_size = 1Gapc.ttl = 0apc.user_ttl = 0ap ...

  10. C# rmi例子

    接口定义 实体定义,注意需要序列化 using System; namespace Interface { [Serializable] public class DataEntity { publi ...