基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
B君和L君要玩一个游戏。刚开始有n个正整数 ai 。
双方轮流操作。每次操作,选一个正整数x,将其移除,再添加7个数字 x1,x2...x7 。要求对于 xi ,满足 0<=xi<x 且 x&xi=xi
注意0不能被选取,所以这个游戏一定会结束,而谁无法操作谁就失败。
B君根据自己的经验,认为先手胜率高一点,所以B君是先手。
B君想知道自己是否必胜。
双方轮流操作。每次操作,选一个正整数x,将其移除,再添加7个数字 x1,x2...x7 。要求对于 xi ,满足 0<=xi<x 且 x&xi=xi
注意0不能被选取,所以这个游戏一定会结束,而谁无法操作谁就失败。
B君根据自己的经验,认为先手胜率高一点,所以B君是先手。
B君想知道自己是否必胜。
Input
第一行一个整数n (1 <= n <= 100000) 以下n行n个数ai (0 <= a_i < 2^64)
Output
如果先手必胜,输出"B",否则输出"L"。
Input示例
4
1
2
3
4
Output示例
B
//尼姆博弈的变形,sg 值很容易想到,然后异或和即可,坑点在于卡读入

1 # include <cstdio> 2 # include <cstring> 3 # include <cstdlib> 4 # include <iostream> 5 # include <vector> 6 # include <queue> 7 # include <stack> 8 # include <map> 9 # include <bitset> 10 # include <sstream> 11 # include <set> 12 # include <cmath> 13 # include <algorithm> 14 # pragma comment(linker,"/STACK:102400000,102400000") 15 using namespace std; 16 # define LL long long 17 # define pr pair 18 # define mkp make_pair 19 # define lowbit(x) ((x)&(-x)) 20 # define PI acos(-1.0) 21 # define INF 0x3f3f3f3f 22 # define eps 1e-8 23 # define MOD 1000000007 24 25 namespace fastIO{ 26 #define BUF_SIZE 100000 27 #define OUT_SIZE 100000 28 #define ll long long 29 //fread->read 30 bool IOerror=0; 31 inline char nc(){ 32 static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; 33 if (p1==pend){ 34 p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); 35 if (pend==p1){IOerror=1;return -1;} 36 //{printf("IO error! ");system("pause");for (;;);exit(0);} 37 } 38 return *p1++; 39 } 40 inline bool blank(char ch){return ch==' '||ch==' '||ch==' '||ch==' ';} 41 inline void read(int &x){ 42 bool sign=0; char ch=nc(); x=0; 43 for (;blank(ch);ch=nc()); 44 if (IOerror)return; 45 if (ch=='-')sign=1,ch=nc(); 46 for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 47 if (sign)x=-x; 48 } 49 inline void read(ll &x){ 50 bool sign=0; char ch=nc(); x=0; 51 for (;blank(ch);ch=nc()); 52 if (IOerror)return; 53 if (ch=='-')sign=1,ch=nc(); 54 for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 55 if (sign)x=-x; 56 } 57 inline void read(double &x){ 58 bool sign=0; char ch=nc(); x=0; 59 for (;blank(ch);ch=nc()); 60 if (IOerror)return; 61 if (ch=='-')sign=1,ch=nc(); 62 for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 63 if (ch=='.'){ 64 double tmp=1; ch=nc(); 65 for (;ch>='0'&&ch<='9';ch=nc())tmp/=10.0,x+=tmp*(ch-'0'); 66 } 67 if (sign)x=-x; 68 } 69 inline void read(char *s){ 70 char ch=nc(); 71 for (;blank(ch);ch=nc()); 72 if (IOerror)return; 73 for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch; 74 *s=0; 75 } 76 inline void read(char &c){ 77 for (c=nc();blank(c);c=nc()); 78 if (IOerror){c=-1;return;} 79 } 80 //getchar->read 81 inline void read1(int &x){ 82 char ch;int bo=0;x=0; 83 for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1; 84 for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar()); 85 if (bo)x=-x; 86 } 87 inline void read1(ll &x){ 88 char ch;int bo=0;x=0; 89 for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1; 90 for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar()); 91 if (bo)x=-x; 92 } 93 inline void read1(double &x){ 94 char ch;int bo=0;x=0; 95 for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1; 96 for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar()); 97 if (ch=='.'){ 98 double tmp=1; 99 for (ch=getchar();ch>='0'&&ch<='9';tmp/=10.0,x+=tmp*(ch-'0'),ch=getchar()); 100 } 101 if (bo)x=-x; 102 } 103 inline void read1(char *s){ 104 char ch=getchar(); 105 for (;blank(ch);ch=getchar()); 106 for (;!blank(ch);ch=getchar())*s++=ch; 107 *s=0; 108 } 109 inline void read1(char &c){for (c=getchar();blank(c);c=getchar());} 110 //scanf->read 111 inline void read2(int &x){scanf("%d",&x);} 112 inline void read2(ll &x){ 113 #ifdef _WIN32 114 scanf("%I64d",&x); 115 #else 116 #ifdef __linux 117 scanf("%lld",&x); 118 #else 119 puts("error:can't recognize the system!"); 120 #endif 121 #endif 122 } 123 inline void read2(double &x){scanf("%lf",&x);} 124 inline void read2(char *s){scanf("%s",s);} 125 inline void read2(char &c){scanf(" %c",&c);} 126 inline void readln2(char *s){gets(s);} 127 //fwrite->write 128 struct Ostream_fwrite{ 129 char *buf,*p1,*pend; 130 Ostream_fwrite(){buf=new char[BUF_SIZE];p1=buf;pend=buf+BUF_SIZE;} 131 void out(char ch){ 132 if (p1==pend){ 133 fwrite(buf,1,BUF_SIZE,stdout);p1=buf; 134 } 135 *p1++=ch; 136 } 137 void print(int x){ 138 static char s[15],*s1;s1=s; 139 if (!x)*s1++='0';if (x<0)out('-'),x=-x; 140 while(x)*s1++=x%10+'0',x/=10; 141 while(s1--!=s)out(*s1); 142 } 143 void println(int x){ 144 static char s[15],*s1;s1=s; 145 if (!x)*s1++='0';if (x<0)out('-'),x=-x; 146 while(x)*s1++=x%10+'0',x/=10; 147 while(s1--!=s)out(*s1); out(' '); 148 } 149 void print(ll x){ 150 static char s[25],*s1;s1=s; 151 if (!x)*s1++='0';if (x<0)out('-'),x=-x; 152 while(x)*s1++=x%10+'0',x/=10; 153 while(s1--!=s)out(*s1); 154 } 155 void println(ll x){ 156 static char s[25],*s1;s1=s; 157 if (!x)*s1++='0';if (x<0)out('-'),x=-x; 158 while(x)*s1++=x%10+'0',x/=10; 159 while(s1--!=s)out(*s1); out(' '); 160 } 161 void print(double x,int y){ 162 static ll mul[]={1,10,100,1000,10000,100000,1000000,10000000,100000000, 163 1000000000,10000000000LL,100000000000LL,1000000000000LL,10000000000000LL, 164 100000000000000LL,1000000000000000LL,10000000000000000LL,100000000000000000LL}; 165 if (x<-1e-12)out('-'),x=-x;x*=mul[y]; 166 ll x1=(ll)floor(x); if (x-floor(x)>=0.5)++x1; 167 ll x2=x1/mul[y],x3=x1-x2*mul[y]; print(x2); 168 if (y>0){out('.'); for (size_t i=1;i<y&&x3*mul[i]<mul[y];out('0'),++i); print(x3);} 169 } 170 void println(double x,int y){print(x,y);out(' ');} 171 void print(char *s){while (*s)out(*s++);} 172 void println(char *s){while (*s)out(*s++);out(' ');} 173 void flush(){if (p1!=buf){fwrite(buf,1,p1-buf,stdout);p1=buf;}} 174 ~Ostream_fwrite(){flush();} 175 }Ostream; 176 inline void print(int x){Ostream.print(x);} 177 inline void println(int x){Ostream.println(x);} 178 inline void print(char x){Ostream.out(x);} 179 inline void println(char x){Ostream.out(x);Ostream.out(' ');} 180 inline void print(ll x){Ostream.print(x);} 181 inline void println(ll x){Ostream.println(x);} 182 inline void print(double x,int y){Ostream.print(x,y);} 183 inline void println(double x,int y){Ostream.println(x,y);} 184 inline void print(char *s){Ostream.print(s);} 185 inline void println(char *s){Ostream.println(s);} 186 inline void println(){Ostream.out(' ');} 187 inline void flush(){Ostream.flush();} 188 //puts->write 189 char Out[OUT_SIZE],*o=Out; 190 inline void print1(int x){ 191 static char buf[15]; 192 char *p1=buf;if (!x)*p1++='0';if (x<0)*o++='-',x=-x; 193 while(x)*p1++=x%10+'0',x/=10; 194 while(p1--!=buf)*o++=*p1; 195 } 196 inline void println1(int x){print1(x);*o++=' ';} 197 inline void print1(ll x){ 198 static char buf[25]; 199 char *p1=buf;if (!x)*p1++='0';if (x<0)*o++='-',x=-x; 200 while(x)*p1++=x%10+'0',x/=10; 201 while(p1--!=buf)*o++=*p1; 202 } 203 inline void println1(ll x){print1(x);*o++=' ';} 204 inline void print1(char c){*o++=c;} 205 inline void println1(char c){*o++=c;*o++=' ';} 206 inline void print1(char *s){while (*s)*o++=*s++;} 207 inline void println1(char *s){print1(s);*o++=' ';} 208 inline void println1(){*o++=' ';} 209 inline void flush1(){if (o!=Out){if (*(o-1)==' ')*--o=0;puts(Out);}} 210 struct puts_write{ 211 ~puts_write(){flush1();} 212 }_puts; 213 inline void print2(int x){printf("%d",x);} 214 inline void println2(int x){printf("%d ",x);} 215 inline void print2(char x){printf("%c",x);} 216 inline void println2(char x){printf("%c ",x);} 217 inline void print2(ll x){ 218 #ifdef _WIN32 219 printf("%I64d",x); 220 #else 221 #ifdef __linux 222 printf("%lld",x); 223 #else 224 puts("error:can't recognize the system!"); 225 #endif 226 #endif 227 } 228 inline void println2(ll x){print2(x);printf(" ");} 229 inline void println2(){printf(" ");} 230 #undef ll 231 #undef OUT_SIZE 232 #undef BUF_SIZE 233 }; 234 using namespace fastIO; 235 # define MX 10005 236 /**************************/ 237 int main() 238 { 239 LL n; 240 fastIO::read(n); 241 //scanf("%lld",&n); 242 LL sg = 0; 243 for (int i=1;i<=n;i++) 244 { 245 LL sb; 246 fastIO::read(sb); 247 //scanf("%lld",&sb); 248 LL pp=0; 249 250 while (sb) 251 { 252 if (sb&(1LL)) pp++; 253 sb/=2; 254 } 255 256 sg^=7*(pp-1); 257 } 258 259 if (sg==0) 260 printf("L "); 261 else 262 printf("B "); 263 return 0; 264 }