codeforces 463c
来源:互联网 发布:c语言有什么用? 编辑:程序博客网 时间:2024/06/05 14:12
//codeforces 463c //题目大意://在n*n的网格里每一个网格都有一个数字 在这个网格上放置2个主教//主教会攻击在和他同一个对角线上的数字 而每攻击一个数字就会获得//这个数字大小的钱 怎么放置两个主教 才可使两个主教不攻击同一个元素//并且获得最多的钱//解题思路://要想两个主教不攻击同一个元素 则两个主教必须在不同的奇偶格里(行号+列号)//计算每个格子上放置主教所获的钱 利用贪心算法思想从奇里取最大的 再从偶格里取最大的#include <iostream>using namespace std;const int nmax=2001;int n,cell[nmax][nmax],d[2*nmax],p[2*nmax];int main(int argc,char *argv[]){ for(int i=0;i<2*nmax;i++) { d[i]=p[i]=0; } cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { cin>>cell[i][j]; d[i+j]+=cell[i][j];//求所对应的的副对角线的和 p[i-j+n]+=cell[i][j];//求所对应的的主对角线的和 } int even,old,evenx,eveny,oldx,oldy; even=old=-1; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if((i+j)&1)//奇数的情况下的最大值 { if(old<d[i+j]+p[i-j+n]-cell[i][j])//更新对角线的值 { old=d[i+j]+p[i-j+n]-cell[i][j]; oldx=i; oldy=j; } } else//偶数下的最大值 { if(even<d[i+j]+p[i-j+n]-cell[i][j])//更新对角线的值 { even=d[i+j]+p[i-j+n]-cell[i][j]; evenx=i; eveny=j; } } } cout<<even+old<<endl; if(evenx<oldx) { cout<<evenx<<" "<<eveny<<" "<<oldx<<" "<<oldy<<endl; } else if(evenx>oldx) { cout<<oldx<<" "<<oldy<<" "<<evenx<<" "<<eveny<<endl; } else if(eveny<oldy) { cout<<evenx<<" "<<eveny<<" "<<oldx<<" "<<oldy<<endl; } else { cout<<oldx<<" "<<oldy<<" "<<evenx<<" "<<eveny<<endl; } return 0;}
0 0
- codeforces 463c
- 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 463C(对角线技巧)
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- 变量和运算符的使用、JAVA控制语句
- iOS开发---绘图
- android studio 更新 Gradle错误解决方法
- HDU-1166-敌兵布阵-单点更新
- 第八章的作业--8.15
- codeforces 463c
- 冒泡选择
- Contains Duplicate III
- Android清单文件详解(三)----应用程序的根节点<application>
- 困扰已久——DataGridView控件填充数据时自动添加列
- 数据库查询并存放
- Linux系统防CC攻击自动拉黑IP增强版Shell脚本
- VS2012 + SWIG Python
- zoj 2588 Burning Bridges(求割边+对重边的处理)