Codeforces 463C Gargari and Bishops【模拟】
来源:互联网 发布:mac vmware 安装win10 编辑:程序博客网 时间:2024/06/04 18:58
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 getx 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 integersaij(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), wherexi is the number of the row where thei-th bishop should be placed, yi is the number of the column where thei-th bishop should be placed. Consider rows are numbered from 1 ton from top to bottom, and columns are numbered from 1 ton from left to right.
If there are several optimal solutions, you can print any of them.
41 1 1 12 1 1 01 1 1 01 0 0 1
122 2 3 2
题目大意:
给你一个N*N大小的格子,我们可以在上边放两个棋子,对应获得棋子所在两个对角线的价值,我们现在想要得到一个放置的方式,使得两个棋子没有共同攻击得到的位子存在
问怎样放置能够获得最大值。
思路:
1、思路很好建立,对应我们希望两个棋子没有重叠点,那么我们将图按照坐标(x+y)的奇偶性染成黑白两色。那么我们只要保证一个棋子放在黑色位子上, 另外一个棋子放在白色位子上即可,对应我们想要得到最大价值,那么我们只要每种情况的维护最大值即可。
2、那么我们求出每一种对角线的和,然后对应枚举点,维护最大值加和即可。
#include<stdio.h>#include<string.h>using namespace std;#define ll __int64#define mid 3000ll r[2005*4];ll l[2005*4];ll a[2005][2005];int main(){ int n; while(~scanf("%d",&n)) { memset(l,0,sizeof(l)); memset(r,0,sizeof(r)); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { scanf("%I64d",&a[i][j]); l[i+j]+=a[i][j]; r[i-j+mid]+=a[i][j]; } } ll ans1=-1,ans2=-1; int xx,yy,xxx,yyy; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { ll val=r[i-j+mid]+l[i+j]-a[i][j]; if((i+j)%2==0) { if(val>ans1) { ans1=val; xx=i+1,yy=j+1; } } if((i+j)%2==1) { if(val>ans2) { ans2=val; xxx=i+1,yyy=j+1; } } } } printf("%I64d\n%d %d %d %d\n",ans1+ans2,xx,yy,xxx,yyy); }}
- Codeforces 463C Gargari and Bishops【模拟】
- Codeforces 463C Gargari and Bishops(贪心)
- Codeforces 463C Gargari and Bishops 题解
- Codeforces 463C. Gargari and Bishops
- Codeforces 463C Gargari and Bishops
- CodeForces 463C - Gargari and Bishops
- 【CODEFORCES】C. Gargari and Bishops
- 【CodeForces】Gargari and Bishops
- CodeForces】Gargari and Bishops
- Codeforces 463C Gargari and Bishops 贪心+规律
- Codeforces 436C Gargari and Bishops
- CF 463C Gargari and Bishops (贪心)
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
- Codeforces Round 264(div2) C. Gargari and Bishops
- Codeforces #264 (Div. 2) C. Gargari and Bishops
- COdeforces Round #264 (Div. 2) C. Gargari and Bishops
- Codeforces Round #264 (Div. 2) C. Gargari and Bishops
- Codeforces Round #264 (Div. 2)-C. Gargari and Bishops
- python基础之列表的索引
- Linux下提取bmp图片颜色信息生成fb文件并用framebuffer显示
- 排序算法之交换排序
- 爱技术
- InetAddress(IP类)
- Codeforces 463C Gargari and Bishops【模拟】
- uva116 unidirectional TSP 单向TSP (DP)
- bitcoin的学习网站
- 普林斯顿微积分读本——第一章 函数、图像和直线(读书笔记)
- 淡化系统Bar
- Java——泛型
- LBaaS 实现机制 - 每天5分钟玩转 OpenStack(125)
- 类型 List 不是通用的;不能使用参数 <String> 将它参数化
- 一个奇数N的立方等于N个连续奇数之和