您的位置:首页 > 其它

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

#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: