Codeforces 463C Gargari and Bishops(贪心)
2014-08-30 21:30
295 查看
题目链接:Codeforces 463C Gargari and Bishops
题目大意:在一个n∗n的国际象棋的棋盘上放两个主教,要求不能有位置同时被两个主教攻击到,然后被一个主教攻击到的位置上获得得分。求得分的最大值。
解题思路:黑白格分开考虑最大值,注意全0的时候。
题目大意:在一个n∗n的国际象棋的棋盘上放两个主教,要求不能有位置同时被两个主教攻击到,然后被一个主教攻击到的位置上获得得分。求得分的最大值。
解题思路:黑白格分开考虑最大值,注意全0的时候。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define add(a,b) ((a)+(b)) #define del(a,b) ((a)-(b)+2000) const int maxn = 2005; typedef long long ll; int n; ll g[maxn][maxn], l[maxn*2], r[maxn*2]; int main () { scanf("%d", &n); memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { scanf("%lld\n", &g[i][j]); l[add(i, j)] += g[i][j]; r[del(i, j)] += g[i][j]; } int odd_x, odd_y, even_x, even_y; ll max_odd = -1, max_even = -1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if ((i+j)&1) { if (max_odd < l[add(i, j)] + r[del(i, j)] - g[i][j]) { max_odd = l[add(i, j)] + r[del(i, j)] - g[i][j]; odd_x = i; odd_y = j; } } else { if (max_even < l[add(i, j)] + r[del(i, j)] - g[i][j]) { max_even = l[add(i, j)] + r[del(i, j)] - g[i][j]; even_x = i; even_y = j; } } } } printf("%lld\n%d %d %d %d\n", max_even + max_odd, odd_x, odd_y, even_x, even_y); return 0; }
相关文章推荐
- Codeforces 463C. Gargari and Bishops
- CodeForces 463C - Gargari and Bishops
- 【CodeForces】Gargari and Bishops
- G - Gargari and Bishops-贪心暴力
- Codefroces 463C Gargari and Bishops(记忆化搜索暴力一下)
- 【CODEFORCES】C. Gargari and Bishops
- 【CodeForces】Gargari and Bishops
- Codeforces 526C - Om Nom and Candies(贪心)
- codeforces 798 D. Mike and distribution 二维贪心
- 【CodeForces】508C - Anya and Ghosts(贪心 & 模拟)
- CodeForces 628 C. Bear and String Distance(贪心)
- Codeforces Round #264 (Div. 2) C. Gargari and Bishops
- codeforces 798C - Mike and gcd problem 贪心
- Codeforces 492C Vanya and Exams【贪心】
- CodeForces 731B-Coupons and Discounts(贪心 模拟)
- CodeForces 261A Maxim and Discounts [想法/贪心题]
- codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
- Codeforces 719C Efim and Strange Grade【贪心】
- codeforces 798 D. Mike and distribution 二维贪心
- Codeforces 719C Efim and Strange Grade 贪心+模拟