【Codeforces Round #693 (Div. 3) D】Even-Odd Game
阿新 • • 發佈:2021-01-08
技術標籤:githubadbmarkdownvisual studiogui
題目連結
翻譯
translation
題解
貪心,隨便想想也能猜到,排序。然後哪一方最大的數字大(奇數和偶數),就搶對方的(對方的奇偶性數字大),或者拿自己的(自己的奇偶性大)。
這樣,對於拿的那個人來說收益總是最大的。
不夠了就隨遇而安就行。。
程式碼
#include <bits/stdc++.h> #define lson l,mid,rt*2 #define rson mid+1,r,rt*2+1 #define LL long long using namespace std; const int N = 2e5; int n; int a[N+10],b[2][N+10]; LL f[N+10]; int main(){ ios::sync_with_stdio(0),cin.tie(0); int T; cin >> T; while (T--){ cin >> n; int cnt[2]; cnt[0] = cnt[1] = 0; for (int i = 1;i <= n; i++){ cin >> a[i]; int o = a[i]%2; cnt[o]++; b[o][cnt[o]] = a[i]; } for (int i = 0;i < 2; i++){ sort(b[i]+1,b[i]+1+cnt[i]); } LL scoreAlice = 0,scoreBob = 0; for (int i = 1;i <= n; i++){ if (i%2==1){ //Alice turn he like even if (cnt[0] == 0){ cnt[1]--; continue; } if (cnt[1] == 0 || b[0][cnt[0]]>=b[1][cnt[1]]){ scoreAlice+=b[0][cnt[0]]; cnt[0]--; }else{ cnt[1]--; } }else{ if (cnt[1] == 0){ cnt[0]--; continue; } if (cnt[0] == 0 || b[1][cnt[1]]>=b[0][cnt[0]]){ scoreBob+=b[1][cnt[1]]; cnt[1]--; }else{ cnt[0]--; } } } if (scoreAlice==scoreBob){ cout <<"Tie"<<endl; }else if (scoreAlice>scoreBob){ cout <<"Alice"<<endl; }else{ cout <<"Bob"<<endl; } } return 0; }