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;}