Codeforces 451C Predict Outcome of the Game(暴力),codeforces451c
題目串連:Codeforces 451C Predict Outcome of the Game
題目大意:題意有點坑,就是三支球隊有n場比賽,錯過了k場,即這k場比賽不知道輸贏,只知道第一支球隊和第二支球隊勝局情況差d1,第二和第三差d2,問說最後有沒有可能三支隊伍勝局數相同。
解題思路:考慮四種情況下的場數u,是否為3的倍數,u/3後是否比當前情況下勝局數最高的隊伍大,並且還要判斷該情況是否可行。
#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;}