Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game
来源:互联网 发布:.me的域名不能注册了 编辑:程序博客网 时间:2024/05/16 16:07
首先,如果n%3 != 0,肯定不会使得三个队伍平手,输出“no”。
设三个队在前K场比赛中分别赢了x1,x2,x3场,有|x1 - x2| = d1, | x2 - x3| = d2。
由于d1,d2分别有正负,那么共分为四种情况:
{x1 - x2 = d1, x2 - x3 = d2},{x1 - x2 = d1, x3 - x2 = d2},{x2 - x1 = d1, x2 - x3 = d2},{x2 - x1 = d1,x3 - x2 = d2}。
我们分别解出这四个方程中的符合题意的解,若要使最后三个队赢的次数相同,只要x1 <= n/3 && x2 <= n/3 && x3 <= n/3即可,前提是它们都大于等于0。
#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>#define eps 1e-9#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;template<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}int main() { int T; ll n,k,d1,d2; ll x1,x2,x3; read(T); while(T--) { read(n);read(k);read(d1)&read(d2); if(n%3!=0) { printf("no\n"); continue; } int flag=0; for(int i=0;i<=3;i++) { if(i==0) { if((k+d2+2*d1)>=0&&(k+d2+2*d1)%3==0) { x1=(k+d2+2*d1)/3; x2=x1-d1; x3=x2-d2; } else continue; } else if(i==1) { if((k-d2+2*d1)>=0&&(k-d2+2*d1)%3==0) { x1=(k-d2+2*d1)/3; x2=x1-d1; x3=x2+d2; } else continue; } else if(i==2) { if((k+d2-2*d1)>=0&&(k+d2-2*d1)%3==0) { x1=(k+d2-2*d1)/3; x2=x1+d1; x3=x2-d2; } else continue; } else if(i==3) { if((k-d2-2*d1)>=0&&(k-d2-2*d1)%3==0) { x1=(k-d2-2*d1)/3; x2=x1+d1; x3=x2+d2; } else continue; } if(x1>=0&&x2>=0&&x3>=0&&x1<=n/3&&x2<=n/3&&x3<= n/3) flag=1; } if(flag) printf("yes\n"); else printf("no\n"); } return 0; }
0 0
- Codeforces #258 (Div. 2) C. Predict Outcome of the Game
- codeforces 258(Div.2) C. Predict Outcome of the Game
- Codeforces Div. 2 #258-C. Predict Outcome of the Game
- Codeforces Round #258 (Div. 2) C - Predict Outcome of the Game
- Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game
- Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game
- codeforces--C. Predict Outcome of the Game
- Codeforces Round #258 (Div. 2/C)/Codeforces451C_Predict Outcome of the Game(枚举)
- Codeforces 451C Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game(暴力)
- CodeForces 451 C. Predict Outcome of the Game
- Codeforces 451C. Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game (枚举+YY)
- 451 C. Predict Outcome of the Game
- 451C - Predict Outcome of the Game
- CF 451 C Predict Outcome of the Game(数学题)
- Codeforces Round #428 (Div. 2) Game of the Rows (思维)
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- java学习_04_面向对象编程思想-类
- java实现约瑟夫问题
- java的动态绑定与静态绑定
- java中四种引用类型
- java中引用的原理
- Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game
- java参数传递
- Java代码编写的30条建议
- 全面介绍Windows内存管理机制及C++内存分配实例(一):进程空间
- java内存管理_堆和栈_内存泄露…
- java学习_04.1_参数传递
- 类分解器JavaP--分析Java字节…
- java谜题之等或不等
- get trace name