E. Anna and the Valentine's Day Gift
https://codeforces.com/contest/1931/problem/E
题意:给定n个数字和m,A和B玩游戏,A先手。A可以反转任意数字,B可以将任意两个数字连接。问最后谁能赢?如果最后剩下的数字<10^m,则A赢,否则B赢。
思路:应该算是模拟题,只要搞清楚两个玩家的最优策略即可。A肯定是优先找末尾0最多的数进行翻转,这样可以让最终结果的位数尽可能的少。B肯定是优先保末尾0最多的数,而A先手,所以就看最终剩下的那一个数字的位数是多少即可。
总结:上午做的,但是WA了,下午来找bug,才发现在取末尾0的时候逻辑错了,之前写的是只要x % 10 == 0就算做一位末尾0。。导致多加了0,像10007这种数,本来没有A优化的空间,但是也算进去了。
inline void solve(){
int n, m;
cin >> n >> m;
int tot = 0;
vector<int> zeros;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
int cnt = 0;
while (x && x % 10 == 0) {
tot ++;
cnt ++;
x /= 10;
}
while (x) {
tot ++;
x /= 10;
}
if (cnt) {
zeros.push_back(cnt);
}
}
sort(zeros.rbegin(), zeros.rend());
n = (int)zeros.size();
for (int i = 0; i < n; i += 2) {
tot -= zeros[i];
}
cout << (tot > m ? "Sasha" : "Anna") << '\n';
}

浙公网安备 33010602011771号