Codeforces Round #264 (Div. 2) C
题目:
3 seconds
256 megabytes
standard input
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).
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.
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.
4
1 1 1 1
2 1 1 0
1 1 1 0
1 0 0 1
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的更多相关文章
- Codeforces Round #264 (Div. 2)
http://codeforces.com/contest/463 这场是我人生第一场cf啊.. 悲剧处处是啊. 首先,看不懂题,完全理解不了啊.都是wa了好几次才过的 所以a和b这两sb题我做了1个 ...
- Codeforces Round #264 (Div. 2) E. Caisa and Tree 树上操作暴力
http://codeforces.com/contest/463/problem/E 给出一个总节点数量为n的树,每个节点有权值,进行q次操作,每次操作有两种选项: 1. 询问节点v到root之间的 ...
- Codeforces Round #264 (Div. 2) D. Gargari and Permutations 多序列LIS+dp好题
http://codeforces.com/contest/463/problem/D 求k个序列的最长公共子序列. k<=5 肯定 不能直接LCS 网上题解全是图论解法...我就来个dp的解法 ...
- Codeforces Round #264 (Div. 2) C. Gargari and Bishops 主教攻击
http://codeforces.com/contest/463/problem/C 在一个n∗n的国际象棋的棋盘上放两个主教,要求不能有位置同时被两个主教攻击到,然后被一个主教攻击到的位置上获得得 ...
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
称号: 意甲冠军:给定一个矩阵,每格我们有一个数,然后把两个大象,我希望能够吃的对角线上的所有数字.我问两个最大的大象可以吃值. 分析:这种想法是暴力的主题,计算出每一格放象的话能得到多少钱,然后求出 ...
- Codeforces Round #264 (Div. 2) D
题意: 给出最多5个序列,问这几个序列的最长公共子序列的长度是多少. solution : 脑抽级别我是,第一个序列每个数字位置固定,这样只要维护一个k-1维的偏序集就好了.然后在保证每个位置合法的情 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- org.unsaved transient instance - save the transient instance before flushing: bug解决方案
最近开发和学习过程中,遇到很多零碎的知识点,在此简单地记录下: 1.遇如下bug: org.unsaved transient instance - save the transient instan ...
- C# 异步操作 async await 的用法
1. async与 await 成对出现 async 在方法前使用 ,方法体面面用 await . 2. 使用async 和await定义异步方法不会创建新线程. 3.await 后面一定是一个扫行 ...
- Name-based virtual servers 给予名称的虚拟服务
nginx first decides which server should process the request. Let’s start with a simple configuration ...
- 排列组合+组合数取模 HDU 5894
// 排列组合+组合数取模 HDU 5894 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 // 思路: // 定好m个人 相邻人之间k个座位 剩下就剩n-( ...
- python堡垒机
堡垒机 windows下安装python3的paramiko模块后一些报错总结: error: Unable to find vcvarsall.bat [官网对此问题的描述] : https://d ...
- CreateProcess error=206, The filename or extension is too long"的一个解决方案
在实际项目中我使用antrun 和 closure-compiler压缩JS项目.然后我就使用如下代码: 首先加入依赖. <dependency> <groupId>com.g ...
- Android Audio遇到播放无声时的分析
在Android Audio开发过程中,有遇到播放ringtone时无声,但播放Music可以听到声音,关于无声问题的分析,在此做个笔记,方便以后回顾. 分析方向: 1:在音量控制面板中确认该音频流对 ...
- 在Cubieboard上关闭irqbalance服务避免内存泄漏
十一一个假期回来,顺手看了看自己的cubieboard运行状态怎么样 aria2正常: btsync正常: samba正常: 很好, 顺手htop一下,已经开机了13天了,CPU使用率4%,内存使用率 ...
- mysql create table - data_type length -- clwu
mysql create table 时,有时需要指定 data_type length http://dev.mysql.com/doc/refman/5.5/en/create-table.ht ...
- Cocos2d-x项目移植到WP8小记
Cocos2d-x项目移植到WP8小记 作者: K.C. 日期: 10/24/2013 Date: 2013-10-24 00:33 Title: Cocos2d-x项目移植到WP8小记 Tags: ...