https://www.luogu.com.cn/problem/P2599
全部不为1的时候
如果面临两部分相等,那么后手赢
否则先手赢
#include<bits/stdc++.h> using namespace std; int t,n,a1,an,c; int main() { //freopen("in","r",stdin); ios::sync_with_stdio(0); cin >> t; while(t--){ cin >> n; for(int i = 1; i <= n; i++){ int g; cin >> g; if(g == 1) c++; if(i == 1) a1 = g; if(i == n) an = g; } if(c == n){ if(n & 1) cout << 1 << endl; else cout << 0 << endl; }else{ if(abs(a1 - an) <= 1 && a1 != 1 && an != 1) cout << 0 << endl; else cout << 1 << endl; } } return 0; }