Codeforces 451C Predict Outcome of the Game (violent), codeforces451c

Source: Internet
Author: User

Codeforces 451C Predict Outcome of the Game (violent), codeforces451c

Question connection: Codeforces 451C Predict Outcome of the Game

The question is a bit pitfall, that is, three teams have n games and Miss k games, that is, these k games do not know whether to win or lose, I only know that the winner of the first and second teams is d1, while the winner of the second and third teams is d2. I asked if the number of the three teams is the same.

Solution: Consider whether the number of game u in four cases is a multiple of 3, and whether the number after u/3 is higher than the number of winning teams in the current situation, and determine whether the situation is feasible.

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;ll n, k, d1, d2;bool check (ll u, ll t) {    if (u % 3 || u > n)        return false;    return u / 3 >= t;}bool judge () {    if (n % 3)        return false;    /*        */    if (check(n - k + d1 + d2 * 2, d1 + d2))        return true;    if (check(n - k + 2 * d1 + d2, d1 + d2))        return true;    if (check(n - k + d1 + d2, max(d1, d2)))        return true;    if (check(n - k + 2 * max(d1, d2) - min(d1, d2), max(d1, d2)))        return true;    return false;}int main () {    int cas;    scanf("%d", &cas);    for (int i = 0; i < cas; i++) {        scanf("%lld%lld%lld%lld", &n, &k, &d1, &d2);        printf("%s\n", judge() ? "yes" : "no");    }    return 0;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.