Codeforces 451C Predict Outcome of the Game (枚举+YY)

题意

3个队伍参加n场比赛打完k场之后一号队伍和二号队伍的差为d1,二号队伍和三号队伍的差为d2。求能不能n场比赛之后达到三支队伍平局。

思路

注意这里的一号二号只是标号不是名次,所以我们讨论k场比赛的情况,满足d1、d2的只有五种也就是代码中的五种分别讨论一下就行了。

这里的check要尽量细致。

代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define LL long long
#define lowbit(x) ((x)&(-x))
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1|1
#define MP(a, b) make_pair(a, b)
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const int maxn = 1e5 + 10;
const double eps = 1e-8;
const double PI = acos(-1.0);
typedef pair<int, int> pii;

LL n, k, d1, d2;

bool check(LL a, LL b, LL c)
{
    if (a < 0 || b < 0 || c < 0)
        return 0;
    if (a + b + c > k) return 0;
    if ((k - a - b - c) % 3) return 0;
    LL temp = (a + b + c + n - k);
    if (temp % 3 || max(max(a, b), c) > temp / 3)
        return 0;
    return 1;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n >> k >> d1 >> d2;
        if (check(0, d2, d1 + d2))
            puts("yes");
        else if (check(0, d1, d2))
            puts("yes");
        else if (check(0, d1, d1 - d2))
            puts("yes");
        else if (check(0, d2, d2 - d1))
            puts("yes");
        else if (check(0, d1, d1 + d2))
            puts("yes");
        else
            puts("no");
    }
    return 0;
}
时间: 2024-08-04 16:25:46

Codeforces 451C Predict Outcome of the Game (枚举+YY)的相关文章

Codeforces 451C Predict Outcome of the Game(暴力)

题目连接:Codeforces 451C Predict Outcome of the Game 题目大意:题意有点坑,就是三支球队有n场比赛,错过了k场,即这k场比赛不知道输赢,只知道第一支球队和第二支球队胜局情况差d1,第二和第三差d2,问说最后有没有可能三支队伍胜局数相同. 解题思路:考虑四种情况下的场数u,是否为3的倍数,u/3后是否比当前情况下胜局数最高的队伍大,并且还要判断该情况是否可行. #include <cstdio> #include <cstring> #in

CodeForces 451C Predict Outcome of the Game

Predict Outcome of the Game Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 451C Description There are n games in a football tournament. Three teams are participating in it. Currently k 

Codeforces Round #258 (Div. 2/C)/Codeforces451C_Predict Outcome of the Game(枚举)

解题报告 http://blog.csdn.net/juncoder/article/details/38102391 题意: n场比赛其中k场是没看过的,对于这k场比赛,a,b,c三队赢的场次的关系是a队与b队的绝对值差d1,b队和c队绝对值差d2,求是否能使三支球队的赢的场次相同. 思路: |B-A|=d1 |C-B|=d2 A+B+C=k 这样就有4种情况,分别是: B>A&&C<B B>A&&C>B B<A&&C<

【math】【codeforces】451A Predict Outcome of the Game

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=52099 有三只球队,一共有n场比赛,然后现在进行了k场,不知道输赢,只知道第一和第二的分数差是d1,第二和第三的分数差是d2, 问这样比赛是不是可能出现平局,注意每一场比赛没有平局. 如果n%3 != 0,肯定不会使得三个队伍平手,输出“no”. 设三个队在前K场比赛中分别赢了x1,x2,x3场,有|x1 - x2| = d1, | x2 - x3| = d2. 由于d1,

Codeforces 425A Sereja and Swaps(暴力枚举)

题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内,然后找区间外假设有更大的值就替换掉. 求出每一个区间的最大值,最后记录下全部区间的最大值 代码: By lab104_yifan, contest: Codeforces Round #243 (Div. 2), problem: (C) Sereja and Swaps, Accepted, #

codeforces 629C Famil Door and Brackets (dp + 枚举)

题目链接: codeforces 629C Famil Door and Brackets 题目描述: 给出完整的括号序列长度n,现在给出一个序列s长度为m.枚举串p,q,使得p+s+q是合法的括号串,长度为n,问p,q的取值数目. 解题思路: 枚举p的长度,可以直接得到q的长度.因为要满足在任意位置'(' 数目大于 ’)‘ 的数目,所以统计一下s串中 ’(‘ - ')' 的最小数目minx.dp[i][j] 代表 到位置 i 时,满足 '(' - ')' == j 的情况数目.然后枚举p的 j

Codeforces Round #258 (Div. 2)C(暴力枚举)

就枚举四种情况,哪种能行就是yes了.很简单,关键是写法,我写的又丑又长...看了zhanyl的写法顿时心生敬佩.写的干净利落,简直美如画...这是功力的体现! 以下是zhanyl的写法,转载在此以供学习: #include <vector> #include <list> #include <queue> #include <map> #include <set> #include <deque> #include <stac

Codeforces Round #253 (Div. 2)B(暴力枚举)

就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<map> #include<set> #include<vector> #include<

CodeForces - 598C(高精度几何 排序然后枚举)

传送门: http://codeforces.com/problemset/problem/598/C Nearest vectors time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given the set of vectors on the plane, each of them starting at