题解:CF2156B Strange Machine
首先看到
代码:
#include<bits/stdc++.h>
using namespace std;
char s[25];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int _;
cin >> _;
while(_--)
{
int n,q;
cin >> n >> q;
cin >> s+1;
int A = 0,B = 0;
for(int i = 1;i<=n;++i)
{
A+=s[i] == 'A';
B+=s[i] == 'B';
}
while(q--)
{
int x;
cin >> x;
if(B == 0)
{
cout << x << '\n';
}
else
{
int num = 0;
while(x)
{
for(int i = 1;i<=n;++i)
{
if(!x)
{
break;
}
++num;
if(s[i] == 'A')
{
--x;
}
else
{
x>>=1;
}
}
}
cout << num << '\n';
}
}
}
return 0;
}