Codeforces #264 (Div. 2) C. Gargari and Bishops
来源:互联网 发布:中国移动m823软件 编辑:程序博客网 时间:2024/06/05 04:31
一道暴力题,但是题目有个坑,等到发现的时候已经没什么时间了
坑点就在于题目说要求任意一个棋子不可以同时被两个主教攻击
并不等价于两个主教不再同一条对角线即可
对应的规律应该是行列数相加奇偶性不同
这个题的主要做法就是先求出正反对角线的值
通过这些值计算每个单元格对应的值
然后再用上面的方法找到两个最大的即可
代码如下:
#include <cstdio>#include <iostream>#include <cstring>#define MAXN 2100#define LL long longusing namespace std;int n, x1, x2, y1, y2;LL ans1, ans2;int a[MAXN<<1][MAXN<<1];LL l[(MAXN<<1)+100], r[(MAXN<<1)+100];LL get_l(int i) { int tmpx, tmpy, x = i, y = 1; LL ans = 0ll; tmpx = x; tmpy = y; ans += a[x][y]; while(tmpx!=y || tmpy!=x) { --tmpx; ++tmpy; ans += a[tmpx][tmpy]; } //printf("l[%d] = %lld\n", i, ans); return ans;}LL get_r(int i) { int tmpx, tmpy, x = 1, y = n+1-i; LL ans = 0ll; tmpx = x; tmpy = y; ans += a[x][y]; while(tmpx!=n+1-y || tmpy!=n+1-x) { ++tmpx; ++tmpy; ans += a[tmpx][tmpy]; } //printf("r[%d] = %lld\n", i, ans); return ans;}void get_sum() { LL sum; ans1 = ans2 = 0; for(int i=1; i<=n; ++i) { for(int j=1; j<=n; ++j) { sum = l[i+j-1]+r[i+n-j]-a[i][j]; if((i+j) & 1) { if(sum >= ans1) { ans1 = sum; x1 = i; y1 = j; } } else { if(sum >= ans2) { ans2 = sum; x2 = i; y2 = j; } } //printf("sum[%d][%d] = %lld\n", i, j, sum[i][j]); } }}int main(void) { scanf("%d", &n); for(int i=1; i<=n; ++i) { for(int j=1; j<=n; ++j) { scanf("%d", &a[i][j]); } } int num = 2*n-1; for(int i=1; i<=num; ++i) { l[i] = get_l(i); r[i] = get_r(i); } get_sum(); //printf("cnt = %d\n", cnt); cout << ans1+ans2 << endl; printf("%d %d %d %d\n", x1, y1, x2, y2); return 0;}
0 0
- Codeforces Round #264 (Div. 2) 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 Round #264 (Div. 2) C. Gargari and Bishops 主教攻击
- 【CODEFORCES】C. Gargari and Bishops
- 【CodeForces】Gargari and Bishops
- CodeForces】Gargari and Bishops
- Codeforces Round 264(div2) C. 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【模拟】
- Android源码 简洁的随手记事项目源码
- NYOJ-第三大
- 二叉树先序中序后序遍历思路编程
- NYOJ-小明的难题
- My Note on Algorithmn
- Codeforces #264 (Div. 2) C. Gargari and Bishops
- LeetCode 43 Convert Sorted List to Binary Search Tree
- 关于VTK中缺少动态链接库
- Creating, configuring, and scheduling a local notification
- 黑马程序员_集合
- NYOJ-Take it easy
- JavaEE 和 JavaWeb的区别与联系
- C语言中malloc 动态申请多维数组
- LCS