codeforces 258div2C Predict Outcome of the Game
2014-07-25 15:10
483 查看
题目链接:http://codeforces.com/contest/451/problem/C
解题报告:三个球队之间一共有n场比赛,现在已经进行了k场,不知道每个球队的胜场是多少,如三个球队的胜场分别为a,b,c,那么已知的是:
|a - b | = d1
|b -c | = d2
输入n,k,d1,d2,要你判断有没有可能让三个球队最后的胜场数相同。
只要分四种情况就可以求出a,b,c分别是多少,然后判断是不是满足:
n % 3 == 0
a,b,c都小于n / 3
a >= 0 && b >= 0 && c >= 0
View Code
解题报告:三个球队之间一共有n场比赛,现在已经进行了k场,不知道每个球队的胜场是多少,如三个球队的胜场分别为a,b,c,那么已知的是:
|a - b | = d1
|b -c | = d2
输入n,k,d1,d2,要你判断有没有可能让三个球队最后的胜场数相同。
只要分四种情况就可以求出a,b,c分别是多少,然后判断是不是满足:
n % 3 == 0
a,b,c都小于n / 3
a >= 0 && b >= 0 && c >= 0
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long INT; INT n,k,d1,d2; int judge(INT a,INT b,INT c) { if(n % 3 != 0) return 0; if(a < 0 || b < 0 || c < 0) return 0; if(a + b + c > k) return 0; INT temp = n / 3; if(a > temp || b > temp || c > temp) return 0; return 1; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%lld%lld%lld%lld",&n,&k,&d1,&d2); if(n % 3 != 0) { printf("no\n"); continue; } int flag = 0; INT t = (k + 2 * d1 + d2),a; if(t % 3 == 0) { a = t / 3; if(judge(a,a-d1,a-d1-d2)) flag = 1; } t = (k + 2 * d1 - d2); if(t % 3 == 0) { a = t / 3; if(judge(a,a-d1,a-d1+d2)) flag = 1; } t = (k - 2 * d1 + d2); if(t % 3 == 0) { a = t / 3; if(judge(a,a+d1,a+d1-d2)) flag = 1; } t = (k - 2 * d1 - d2); if(t % 3 == 0) { a = t / 3; if(judge(a,a+d1,a+d1+d2)) flag = 1; } printf(flag? "yes\n":"no\n"); } return 0; }
View Code
相关文章推荐
- CodeForces 451 C. Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game (枚举+YY)
- codeforces--C. Predict Outcome of the Game
- Codeforces 451C Predict Outcome of the Game(暴力)
- Codeforces Div. 2 #258-C. Predict Outcome of the Game
- 451 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 水题
- CF 451 C Predict Outcome of the Game(数学题)
- Codeforces Round #258 (Div. 2/C)/Codeforces451C_Predict Outcome of the Game(枚举)
- cf451C-Predict Outcome of the Game
- Predict Outcome of the Game CodeForces - 451C (分情况讨论)
- 451C - Predict Outcome of the Game
- Codeforces Round #258 (Div. 2) C - Predict Outcome of the Game
- Codeforces Round #258 (Div. 2/C)/Codeforces451C_Predict Outcome of the Game(枚举)
- codeforces 839b 之 Game of the Rows
- Codeforces 839B-Game of the Rows
- codeforces 839 B Game of the Rows
- Codeforces 428(div 2)B. Game of the Rows(思维题)
- 博弈论 —— The Game of Parity ( CodeForces 549C )