Educational Codeforces Round 63 (Rated for Div. 2)B. Game with Telephone Numbers【贪心】

B. Game with Telephone Numbers

A telephone number is a sequence of exactly 1111 digits such that its first digit is 8.

Vasya and Petya are playing a game. Initially they have a string ss of length nn (nn is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string ss becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins.

You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves).

Input

The first line contains one integer nn (13≤n<10513≤n<105, nn is odd) — the length of string ss.

The second line contains the string ss (|s|=n|s|=n) consisting only of decimal digits.

Output

If Vasya has a strategy that guarantees him victory, print YES.

Otherwise print NO.

思路:只需要判断8的数量是否比其他数字多就行了,后面的10位不用管。

#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1|1
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
string s;


int main()
{
    int n;
    scanf("%d", &n);
    cin >> s;
    int a = 0, b = 0;
    for(int i = 0; i < n - 10; ++i)
    {
        if(s[i] == '8')
            a++;
        else
            b++;
    }
    if(a > b)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41785863/article/details/89480820