CodeForce 463C Gargari and Bishops(贪心+暴力)
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
#include<cstdio>
#include<cstring>
const int N = 2005;
typedef long long LL;
LL Map[N][N]; //棋盘
LL L[N*2]; //副对角线元素之和
LL R[N*2]; //主对角线元素之和
int main()
{int n;while(~scanf("%d",&n)) {memset(L, 0, sizeof(L));memset(R, 0, sizeof(R));for(int i = 1; i <= n; i++) {for(int j = 1; j <= n; j++) {scanf("%I64d",&Map[i][j]);L[i+j] += Map[i][j]; //同一条副对角线i+j相同R[i-j+n] += Map[i][j]; //同一条主对角线i-j相同}}int x1 = 1, x2 = 1, y1 = 1, y2 = 2;LL max1 = 0, max2 = 0;for(int i = 1; i <= n; i++) {for(int j = 1; j <= n; j++) {LL tmp = L[i+j] + R[i-j+n] - Map[i][j];if((i+j) % 2 == 0 && tmp > max1) {max1 = tmp;x1 = i;y1 = j;}if((i + j) % 2 == 1 && tmp > max2) {max2 = tmp;x2 = i;y2 = j;}}}printf("%I64d\n", max1 + max2);printf("%d %d %d %d\n", x1, y1, x2, y2);}return 0;
}
CodeForce 463C Gargari and Bishops(贪心+暴力)相关推荐
- codeforces 463C. Gargari and Bishops 解题报告
题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...
- codeforces Gargari and Bishops(很好的暴力)
1 /* 2 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 3 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 4 ...
- hdu3697(贪心+暴力)
题意: 一个人要选课,现在给出每门课的选课开始时间和选课截止时间,这个人会每隔5分钟选一次课,问他最多可以选多少门课. 思路: 我们把没门课按结束时间从小到大排序,结束时间相同按开始时间从小到大排序, ...
- P2354,jzoj3757-[NOI2014]随机数生成器【贪心,暴力】
正题 题目链接:https://www.luogu.com.cn/problem/P2354 解题思路 以1∼n∗m1\sim n*m1∼n∗m的数字组成的n∗mn*mn∗m的矩阵,求一条路径使得路径 ...
- 夺宝奇兵 (优先队列 + 贪心 + 暴力枚举)
题目描述 wls 所在的王国有 n 个居民(不包括 wls),他们共有 m 件神奇的宝物. 对于第 件宝物,wls 可以花费 的金币把它从原来的主人那里买过来. 请问 wls最少要准备多少金币,才 ...
- hdu2037 今年暑假不AC(贪心||暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=2037 题意:中文题不解释.首先是尽人皆知的贪心,用烂了.刚开始入门时候不懂,就跟着人模仿.今天(2016/10/ ...
- hdu-5583 Kingdom of Black and White(数学,贪心,暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5583 Kingdom of Black and White Time Limit: 2000/1000 ...
- hiho 1615 矩阵游戏II [Offer收割]编程练习赛33 Problem A 贪心暴力
把每列取反后所能获得的收益记录下来,然后排序,从高到低一对对的取,大于0就算上. #include <iostream> #include <stdio.h> #include ...
- Codeforces Round #264 (Div. 2) 解题报告
Source: http://codeforces.com/contest/463 打得比较差..第三题想写nlgn的,结果调了很久又wa,以为写挫,过了很久发现做法有问题..最后两题惨淡收场.第四 ...
最新文章
- linux路由介绍,Linux的路由表详细介绍
- hdu 1228-A+B
- java 集合 延迟加载_java-如何测试延迟加载的JPA集合是否已初始化?
- java接口的定义与实现实验报告,赶紧收藏备战金三银四!
- 修改2440里面的FriendlyARM
- 深度学习中的专业英语词汇(by Youki)
- andriod 自定义来电界面功能
- RestClientException: Could not extract response: no suitable HttpMessageConverter found for response
- CleanMyMac X断网激活码免费共享教程免费分享
- 医院信息系统培训心得
- fild与fmul的问题
- 银行卡Bin和Logo
- BZOJ3161 : 孤舟蓑笠翁
- 《异常点检测》 - 第十章阅读记录 - 离散序列的异常点检测
- 黑苹果双系统时间不一致_黑苹果与Windows系统时间不对(不同步)的解决办法...
- 4. 假设一年期定期利率为 3.25%,计算一下需要过多少年,一万元的一年定期存款连本带息能翻番?
- AB test | 学习笔记
- 织梦图集php,织梦怎么为新图集页面增加图片下载功能
- 基于matlab的禁止无功补偿,基于MATLAB的TSC-TCR型静止无功补偿器仿真研究.zip
- 【干货书】Python中的商业分析概念、技术和应用的数据挖掘