CF2255A Hot Potatoes at the Fairy Warehouse 题解
CF2255A Hot Potatoes at the Fairy Warehouse 题解
题目传送门
萌新打的第一场 CF
一道偏思维的题目
题目大意
- 空间复杂度:
O(n)
Code
#include <iostream>
#include <cstring>
using namespace std;
typedef long long Int;
const Int N = 200005;
Int T, n, k, a[N], b[N], ans[2];
char s[N];
void ma1n() {
memset(b, 0, sizeof(b)); // 多测清空!
cin >> n >> k; n*=2;
cin >> (s+1);
for (Int i = 1; i <= n; i++) a[i] = s[i]-'0';
// 直接来到最后一回合
for (Int i = 1; i <= n-1; i++)
// 如果自己手上有,下一个人手里没有,就传给她
if (a[i] == 1 && a[i+1] == 0) b[i+1] = 1;
// 否则只能自己拿着了
else if (a[i] == 1) b[i] = 1;
// 特殊处理一下 2n 号人
if (a[n] == 1 && a[1] == 0) b[1] = 1;
else if (a[n] == 1) b[n] = 1;
// 统计两队手上的土豆数量
ans[0] = ans[1] = 0;
for (Int i = 1; i <= n; i++) ans[i%2] += b[i];
cout << ans[0] << ' ' << ans[1] << endl;
}
int main() {
cin >> T;
while (T--) ma1n();
return 0;
}