Codeforces 一场真正的战斗
题目来源:问题 - 2030C - Codeforces
这道题只需要保证首尾中有一个1或者在字符串中有两个相邻的1,Alice就可以赢。
当首尾有一个1时,Alice 可以优先在靠近1的位置放置or运算符。由于or运算的特性(1orx=1),只要最终表达式中保留这个1并通过or 连接,结果就会是1。即使 Bob 试图用and抵消,Alice 也能通过先手优势确保1最终生效。
有两个相邻的1时,两个相邻的1无论中间放and还是or,结果都是1(1and1=1,1or1=1)。Alice 可以在这两个1之间放置运算符,后续无论 Bob 如何操作,都无法将其变为0,最终结果必然为1
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{int t;cin>>t;while(t--){int n;cin>>n;string stl;cin>>stl;int flag=0;if(stl[0]=='1'||stl[n-1]=='1'){flag=1;}for(int i=0;i<n-1;i++){if(stl[i]=='1'&&stl[i+1]=='1'){flag=1;break;}}if(flag){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}return 0;
}