Problem - A - Codeforces
QUESTION
对于一个给定的序列而言,将其中的连续子序列b用数 mex(b) 来替换
mex(b):最小的不出现在序列b中的非负整数
问,需要多少次操作才能把当前序列中的数全部变成0
RESOLUTION
也可以通过找连续正数块的数量来判定:
CODE
#include<iostream> using namespace std;
void resolution(){ int n, x, t = 0; cin >> n; bool flag = 0; cin >> x; if(x){ flag = 1; t++; } for(int i = 2; i <= n; i++){ cin >> x; if(flag && !x){ t++; flag = 0; } if(!flag && x){ t++; flag = 1; } if(i == n && x) t++; } t /= 2; if(!flag && t == 0) cout << 0 << endl; else if(t >= 2) cout << 2 << endl; else cout << 1 << endl; return ; }
int main(){ ios::sync_with_stdio(0); int T; cin >> T; while(T--){ resolution(); } return 0; }
|