【CODEFORCES】C. Gargari and Bishops
来源:互联网 发布:厦门大学吴春明知乎 编辑:程序博客网 时间:2024/06/05 02:16
题解:这一题看到题目数据不太大,首先想到枚举,然后竟然就这样写出来了......
2个相,不能同时攻击一个细胞,但是又要和最大,我们先处理出左对角线和又对角线的两个和,存在L[I]和R[I]中,然后分割棋盘 为 I+J为奇数的 和I+J为偶数的 这样两种情况分开取出最大值,最后记录输出即可。
分割棋盘这个方法太刁了....
注意要预处理X1 Y1 X2 Y2 不然最后会输出0 0 0 0 。(如果判断的时候是大于等于好像不用)
#include <iostream>#include <cstdio>using namespace std;long long l[4002],r[4002];long long a[2002][2002],n,i,x2,x1,y2,y1,j;int main(){ scanf("%I64d",&n); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf("%I64d",&a[i][j]); // for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) { l[n-j+i]+=a[i][j]; r[i+j-1]+=a[i][j]; } x1=1; y1=1; x2=1; y2=2; long long max1=0,max2=0; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if ((i+j)%2!=0 && max1<l[n-j+i]+r[i+j-1]-a[i][j]) { max1=l[n-j+i]+r[i+j-1]-a[i][j]; x1=i; y1=j; } for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if ((i+j)%2==0 && max2<l[n-j+i]+r[i+j-1]-a[i][j]) { max2=l[n-j+i]+r[i+j-1]-a[i][j]; x2=i; y2=j; } cout <<max1+max2<<endl; cout <<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl; return 0;}
0 0
- 【CODEFORCES】C. Gargari and Bishops
- 【CodeForces】Gargari and Bishops
- CodeForces】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 436C Gargari and Bishops
- Codeforces 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
- Codeforces Round #264 (Div. 2) C - Gargari and Bishops
- Codeforces 463C Gargari and Bishops 贪心+规律
- 万年历方法二
- delphi改变webbrowser中元素的值
- C#-Winform MessageBox使用手册
- OpenCV3.0中CvMat格式转换为Mat格式的方法
- hdoj1025
- 【CODEFORCES】C. Gargari and Bishops
- hdu1695--GCD(欧拉函数+容斥原理)
- python 学习笔记——try,except,else,finally
- JavaScript中substring()与substr()的用法
- KVC的真正强大之处
- 杨辉三角算法
- Python学习(一)
- delphi获得webbrowser中的html文本
- uva10820(数论 +欧拉函数)