CodeForces】Gargari and Bishops
来源:互联网 发布:python运维脚本优势 编辑:程序博客网 时间:2024/05/22 09:40
根据贪心可以知道,放置的教主必须不能相互攻击到(也就是不在一条对角线上)才可以使得结果最大化。
根据观察可以得到教主相互不攻击的条件是他的坐标和互为奇偶(x + y)
之后直接暴力,处理每个坐标对角线的和就好
时间复杂度 0(n ^ 2)
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 2005;LL sum_l[maxn * 10] = {0},sum_r[maxn * 10] = {0};LL mat[maxn][maxn];int main(){ int n,m; LL x; scanf("%d",&n); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ scanf("%I64d",&mat[i][j]); sum_l[i + j] += mat[i][j]; sum_r[n - 1 + j - i] += mat[i][j]; } } //for(int i = 0; i < 2 * n - 1; i++) // printf("%I64d %I64d\n",sum_l[i],sum_r[i]); LL max1 = - 1,max2 = -1; int x1,x2,y1,y2; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){ LL ret = sum_l[i + j] + sum_r[n - 1 + j - i] - mat[i][j]; if(((i + j) & 1) && ret > max1){ max1 = ret; x1 = i; y1 = j; } else if((!((i + j) & 1)) && ret > max2){ max2 = ret; x2 = i; y2 = j; } } LL ans = max1 + max2; printf("%I64d\n",ans); printf("%d %d %d %d\n",x1 + 1,y1 + 1,x2 + 1,y2 + 1); return 0;}
阅读全文
0 0
- 【CodeForces】Gargari and Bishops
- CodeForces】Gargari and Bishops
- 【CODEFORCES】C. Gargari and Bishops
- codeforces C#264. 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
- Face2Face: Real-time Face Capture and Reenactment of RGB Videos 论文翻译
- POJ 2431 Expedition(贪心+优先队列)
- 2017百度之星复赛1001 Arithmetic of Bomb
- HDU
- 【kong系列九】之限流rate-limiting插件
- CodeForces】Gargari and Bishops
- vue项目开发配置信息
- 回溯算法解决数独
- Android 透明状态栏
- Oracle学习笔记之二
- 利用DevicePolicyManager执行屏幕锁定
- Tablayout与视频拖拽相对应
- 广义容斥原理
- 【Unity】实现类似皇室战争使用“火球”将敌人“炸开”效果