Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维

题意:博弈题面  给出一个数字序列 (>=11)  有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢

第一个人先手  数字序列一定是奇数长度

思路: 首先计算一共走多少步 

第二个人想赢只有以下两种方法

想法1:如果第二个人能把8都删掉 那么第二个人肯定赢

想法2: 如果删不掉 那么第二个人肯定从前到后尽可能得删掉8 这样使得第一个人的步数不足删除从前到后 步数+1那个8 的其他字符

否则就是第一人赢,直接模拟即可  

(比赛的时候一直WA 不知道为什么 然后果断重写了一遍才pp(并且没有fft 2333)) 所以重写大法好

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn=3e5+5;
 5 char s[maxn];
 6 int main(){
 7     int n;
 8     scanf("%d",&n);
 9     scanf("%s",s+1);
10     int cnt=0;
11     int huihe=n-11;
12     for(int i=1;i<=n;i++){
13         if(s[i]=='8')cnt++;
14     }
15     int flag=0;
16     int i;
17     for( i=1;i<=n;i++){
18         if(s[i]=='8')flag++;
19         if(flag==huihe/2+1)break;
20     }
21     if(cnt<=huihe/2){
22         cout<<"NO\n";
23     }
24     else {
25         if((i-1-huihe/2)<=huihe/2)cout<<"YES\n";
26         else cout<<"NO\n";
27     }
28     return 0;
29 }
View Code

 

posted @ 2019-04-29 16:43  tttttttttrx  阅读(241)  评论(0编辑  收藏  举报