Educational Codeforces Round 90 (Rated for Div. 2) 參與排名人數12840
[codeforces 1373B] 01 Game 刪除01或10的博弈
總目錄詳見https://blog.csdn.net/mrcrack/article/details/103564004
在線測評地址http://codeforces.com/contest/1373/problem/B
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
B - 01 Game | GNU C++17 | Accepted | 30 ms | 3600 KB |
題目大意:給定一個0,1構成的串,若該串中有10或01就可將其刪除,否則,什麼也做不了。Alice先手,Bob後手,給定一個0,1構成的串,輪到的哪位,什麼都做不了,哪位就判定爲輸。Alice贏,輸出DA,反之,輸出NET。
題中例子模擬如下
1011001
DA
刪除過程如下
1011001→11001→101->1
1011001→11001→110->1
1011001→11001->101->1
1011001→11001->110->1
1011001→10101->101->1
1011001→10110->110->1
1011001→10110->101->1
可以看到,無論怎麼刪,刪除次數是一定的,由min(0的數量,1的數量)決定。
該例子中
0的數量是3
1的數量是4
刪除次數是3
Alice(A),Bob(B)
1(A) 2(B) 3(A)
輪到Bob(B)無法操作,故Alice(A)贏,輸出DA
AC代碼如下:
#include <stdio.h>
#include <string.h>
char s[110];
int cnt[2];
int main(){
int t,n,tot,i;
scanf("%d",&t);
while(t--){
scanf("%s",s);
n=strlen(s),cnt[0]=cnt[1]=0;
for(i=0;i<n;i++)
if(s[i]=='0')cnt[0]++;
else if(s[i]=='1')cnt[1]++;
if(cnt[0]>cnt[1])tot=cnt[1];
else tot=cnt[0];
if(tot%2)printf("DA\n");
else printf("NET\n");
}
}