题目:NCPC
思路:
最大数个数为奇数: 最大数的选手可以通过两两配对消除其他最大数,最后必然剩下一个最大数选手,因此他们都能获胜。 最大数个数为偶数: 所有最大数选手最终会两两消除,因此他们无法获胜。而其他选手可以通过与最大数选手对决,让最大数选手互相消除,从而自己存活到最后。
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){ int T; cin >> T; while(T--){ int n; cin >> n; map<int, vector> mp; string s(n, '0'); for(int i = 0; i < n; i++){ int x; cin >> x; mp[x].push_back(i); } auto &[x, y] = *prev(mp.end()); int t = 1; if(y.size() % 2 == 0){ t = -1; s = string(n, '1'); } for(auto &i : y){ s[i] += t; } cout << s << endl; } }

京公网安备 11010502036488号