codeforces Gargari and Bishops(很好的暴力)
and Codeforces 暴力
2023-09-14 08:57:55 时间
/* 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 数值(只能获取一次)。要求输出两个bishops获取的最大值以及它们所在的位置!
思路:直接暴力!....不错的暴力题目! 首先我们都知道每一条主对角线上的横纵坐标的和相同,每一条副对角线上的横纵坐标的差相同! 那么我们在输入的时候就可以将所有对角线上的数值之和求出来了! 最后我们发现如果要获得最大值,那么还有一条就是两个bishops所在的对角线不能相交在 同一个格子上!只要满足两个bishops的哼纵坐标之和互为奇偶就可以了! 在所有格子中找到横纵坐标之和为奇数并且获得对角线上数值最大的格子和横纵坐标之 和为偶数并且获得对角线上数值最大的格子! 二者最大获得值相加就是最终的答案了! #include iostream #include cstring #include cstdio #include algorithm #define N 2005 using namespace std; typedef long long LL; int num[N][N]; LL sumN[N*2], sumM[N*2]; int n; int main(){ while(scanf("%d", n)!=EOF){ memset(sumN, 0, sizeof(sumN)); memset(sumM, 0, sizeof(sumM)); for(int i=1; i ++i) for(int j=1; j ++j){ scanf("%d", num[i][j]); sumN[i+j]+=num[i][j];//横纵坐标之和为i+j的对角线的数值和 sumM[i-j+n]+=num[i][j];//横纵坐标之差为i-j的对角线的数值和 LL maxOdd=-1, maxEvent=-1, s; int x1, x2, y1, y2; for(int i=1; i ++i) for(int j=1; j ++j){ if((i+j) 1){ if(maxOdd (s=sumN[i+j]+sumM[i-j+n]-num[i][j])){ maxOdd=s;//横纵坐标之和为奇数并且获得对角线上数值最大的格子 x1=i; y1=j; else{ if(maxEvent (s=sumN[i+j]+sumM[i-j+n]-num[i][j])){ maxEvent=s;//横纵坐标之和为偶数并且获得对角线上数值最大的格子 x2=i; y2=j; printf("%lld\n",maxOdd+maxEvent); printf("%d %d %d %d\n", x1, y1, x2, y2); return 0; }
Codeforces-1260-E. Tournament贪心 有n个人,第i个人有力量值i,这n个人中,每次对局两两之间进行solo,如果说一个人的力量之大于他的对手,这个人是赢的,赢得比赛的选手会进入下一轮比赛中。 然而里面有一个人为你的朋友,他或许并不是里面最强的人,要想让朋友成为冠军,就需要对必要的人进行贿赂,求出最少需要花费多少才能使得朋友成为冠军。在每次对局中,都可以进行任意的对局安排,对局安排只取决于自己
相关文章
- [TypeScript] instanceof and Type Guards (getPrototypeOf)
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part5
- [Express] Handle Syncronous and Asyncronous Errors in Express
- [Kubernetes] Kubectl and Pod
- [Functional Programming 101] Crocks.js -- when to use map and when to use chain?
- [Typescript 2] Nullable Types - Avoiding null and undefined Bugs
- Improved dual-mode compressive tracking integrating balanced colour and texture features
- Atitit.mssql 数据库表记录数and 表体积大小统计
- 【Codeforces Round #635 (Div. 2) C】Linova and Kingdom
- 【Codeforces 639B】Bear and Forgotten Tree 3
- 【31.58%】【codeforces 719B】 Anatoly and Cockroaches
- 【77.39%】【codeforces 734A】Anton and Danik
- 【12.78%】【codeforces 677D】Vanya and Treasure
- 【25.33%】【codeforces 552D】Vanya and Triangles
- 【81.82%】【codeforces 740B】Alyona and flowers
- 【codeforces 793A】Oleg and shares
- 【Codeforces Round #425 (Div. 2) A】Sasha and Sticks
- 3GPP TS 29244-g30 中英文对照 | 5.12 Suspend and Resume Notification procedures
- Codeforces Round #305 (Div. 2) D. Mike and Feet