Editorial for Cờ vua
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của flashmt
#include <iostream> #define fr(a,b,c) for (a=b;a<=c;a++) using namespace std; int g[86],d[10]; int main() { int i,j,n; g[1]=g[2]=1; fr(i,3,85) { fr(j,0,9) d[j]=0; d[g[i-2]]=1; fr(j,0,(i-3)/2) d[g[j]^g[i-3-j]]=1; fr(j,0,9) if (!d[j]) break; g[i]=j; } while (cin >> n) { if (n<=85) cout << (g[n]?"White":"Black") << endl; else cout << (g[(n-52)%34+52]?"White":"Black") << endl; } return 0; }
Code mẫu của RR
{$R+,Q+} const g:array[0..102] of integer=( 0,1,1,2,0,3,1,1,0,3,3,2,2,4,0,5,2,2,3,3,0,1,1,3,0,2,1,1,0,4,5,2,7,4, 0,1,1,2,0,3,1,1,0,3,3,2,2,4,4,5,5,2,3,3,0,1,1,3,0,2,1,1,0,4,5,3,7,4, 8,1,1,2,0,3,1,1,0,3,3,2,2,4,4,5,5,9,3,3,0,1,1,3,0,2,1,1,0,4,5,3,7,4,8); var n:longint; begin while not eof do begin read(n); if n<=102 then begin if g[n]>0 then writeln('White') else writeln('Black'); end else begin n:=n mod 34+68; if g[n]>0 then writeln('White') else writeln('Black'); end; end; end.
Code mẫu của hieult
#include <cstdio> #include <iostream> #include <set> //#include <conio.h> using namespace std; int main() { int n; while(scanf("%d",&n)>0) { if(n==0||n==14||n==34||n%34==4||n%34==8||n%34==20||n%34==24||n%34==28) printf("Black\n"); else printf("White\n"); } }
Code mẫu của ll931110
program CHESS_; const input = ''; output = ''; var a: array[0..42] of boolean; rem: array[0..34] of boolean; n: longint; flag: boolean; fi,fo: text; begin assign(fi, input); reset(fi); assign(fo, output); rewrite(fo); fillchar(a, sizeof(a), true); a[0] := false; a[4] := false; a[8] := false; a[14] := false; a[20] := false; a[24] := false; a[28] := false; a[34] := false; a[38] := false; a[42] := false; fillchar(rem, sizeof(rem), true); rem[0] := false; rem[12] := false; rem[16] := false; rem[20] := false; rem[30] := false; while not eof(fi) do begin readln(fi, n); if n <= 42 then flag := a[n] else flag := rem[(n - 42) mod 34]; if flag then writeln(fo, 'White') else writeln(fo, 'Black'); end; close(fo); close(fi); end.
Code mẫu của khuc_tuan
#include "iostream" #include "vector" #include "string.h" using namespace std; #define maxn 5555 int G[maxn]; bool mark[maxn]; int main() { G[0] = 0; G[1] = 1; for(int i=2;i<maxn;++i) { memset( mark, 0, sizeof(mark)); mark[G[i-2]] = true; for(int a=0;a<i;++a) if(i-3-a>=0) mark[G[a] ^ G[i-3-a]] = true; for(int j=0;;++j) if(!mark[j]) { G[i] = j; break; } } int n; while(cin >> n) { if(n<maxn) { if(G[n]==0) cout << "Black\n"; else cout << "White\n"; } else { n -= 262; n %= 34; if(n==0 || n==4 || n==14 || n==18 || n==30) cout << "Black\n"; else cout << "White\n"; } } //system("pause"); return 0; }
Comments