cf1561B. Charmed by the Game
生活随笔
收集整理的這篇文章主要介紹了
cf1561B. Charmed by the Game
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
cf1561B. Charmed by the Game
題意:
兩人輪流發球,有兩種得分的情況,一個是自己發球的回合得分,叫做"holds",另一種是在對方發球的回合得分,叫做"breaks",現在給出比賽結束后兩個人的得分,問你兩個人總的"breaks"的次數有多少種情況。不知道誰先發球,也不知道誰哪個回合取勝,只知道最后的得分
題解:
我們知道兩人得分是x,y,總比賽數量就是x+y,先手發球次數為p=?a+b2?\lceil \frac{a+b}{2} \rceil?2a+b??,后手為q=?a+b2?\lfloor \frac{a+b}{2} \rfloor?2a+b??
現在也不知道誰先發球,我們可以設Alice先發球,設x為Alice輸掉場次為a(0<=a<=p),設Borys輸掉場次為b(0<=b<=q)
如果Alice先發球,枚舉Alice輸的個數a,從0到p,然后有x=(p-a)+y,y=x-(p-a),只要y滿足(0<=y<=q),這就是合法的情況,k就是x+y
Borys發球時同理
代碼:
// Problem: B. Charmed by the Game // Contest: Codeforces - Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) // URL: https://codeforces.com/contest/1561/problem/B // Memory Limit: 512 MB // Time Limit: 2000 ms // Data:2021-08-24 23:07:04 // By Jozky#include <bits/stdc++.h> #include <unordered_map> #define debug(a, b) printf("%s = %d\n", a, b); using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; clock_t startTime, endTime; //Fe~Jozky const ll INF_ll= 1e18; const int INF_int= 0x3f3f3f3f; void read(){}; template <typename _Tp, typename... _Tps> void read(_Tp& x, _Tps&... Ar) {x= 0;char c= getchar();bool flag= 0;while (c < '0' || c > '9')flag|= (c == '-'), c= getchar();while (c >= '0' && c <= '9')x= (x << 3) + (x << 1) + (c ^ 48), c= getchar();if (flag)x= -x;read(Ar...); } template <typename T> inline void write(T x) {if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0'); } void rd_test() { #ifdef LOCALstartTime= clock();freopen("in.txt", "r", stdin); #endif } void Time_test() { #ifdef LOCALendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC); #endif } int main() {//rd_test();int t;read(t);while (t--) {int x, y;read(x, y);if ((x + y) % 2) {int ans= 2 * (min(x, y) + 1);printf("%d\n", ans);int tot= (x + y) / 2 - min(x, y);for (int i= 1; i <= ans; i++) {printf("%d ", tot);tot++;}}else if ((x + y) % 2 == 0) {int ans= (min(x, y) + 1);printf("%d\n", ans);int tot= (x + y) / 2 - min(x, y);for (int i= 1; i <= ans; i++) {int ans= (x + y) / 2 - min(x, y) + 2 * (i - 1);printf("%d ", ans);}}printf("\n");}return 0;//Time_test(); }總結
以上是生活随笔為你收集整理的cf1561B. Charmed by the Game的全部內容,希望文章能夠幫你解決所遇到的問題。