P10187 [USACO24FEB] Palindrome Game B 题解

· · 题解

不难发现所有整除 10,即以 0 结尾的正整数都不是回文数。

因为 1,2,3,4,5,6,7,8,9 都是回文数,而 10 不是,所以当 n\le9 时先手必胜,而 n=10 时先手必输。

假设 x 整除 10,且已知对于所有的 n\le x,当 n 整除 10 时先手输,否则先手赢。显然,x=10 时满足条件。接下来证明:对于任意的 x,当 x 满足条件时,x+10 也满足条件。

现在就成功证明了“若 x 整除 10,且对于所有的 n\le x,当 n 整除 10 时先手输,否则先手赢,那么此时对于所有的 n\le x+10,当 n 整除 10 时先手输,否则先手赢”。而我们又知道 x=10 时满足条件,所以所有的 x 都满足条件,所以只要 n 整除 10 就先手输,否则先手赢。

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int t;cin>>t;while(t--){
        string s;cin>>s;
        if(s.back()=='0')cout<<"E\n";
        else cout<<"B\n";
    } 
    return 0;
}