Educational Codeforces Round 63 (Rated for Div. 2) B题

题目网址:https://codeforc.es/contest/1155/problem/B

题目大意:有两个人A,B博弈,在一串数字中,A先取数,B后取数,最后剩11个数的时候停止,如果第一个数是8,则A胜,反之B胜

题解:取数到最后,只剩11个数,且,A如果要赢,第一个数是8,则A显然是要尽可能的先取前面的非8数,B要先去前面的8,按照这样的策略,只需考虑前面n -10个数取到最后是否有8即可,显然是判断8的数量和其他数的数量的大小即可。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=3e5+7;
 4 char s[maxn];
 5 int main()
 6 {
 7     int n,tot=0;
 8     cin>>n;
 9     scanf("%s",s+1);
10     for(int i=1;i<=n-10;i++) {
11         if(s[i]=='8') tot++;
12         else tot--;
13     }
14     if(tot>0) printf("YES");
15     else printf("NO\n");
16     return 0;
17 } 
View Code

猜你喜欢

转载自www.cnblogs.com/duxing201806/p/10805526.html