Editorial for Cuộc đấu cân não
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
var x,y,t:longint; function win(x,y:longint):boolean; begin if x=y then exit(false); if y-x>x then exit(true); win:=not win(y-x,x); end; begin repeat read(x,y); if x+y=0 then break; if x>y then begin t:=x; x:=y; y:=t; end; if win(x,y) then writeln('T') else writeln('S'); until false; end.
Code mẫu của ladpro98
#include <iostream> using namespace std; bool canWin(int x, int y) { if (x > y) swap(x, y); if (x == y || y == 1) return 0; if (x <= y - x) return 1; return !canWin(x, y - x); } int main() { ios :: sync_with_stdio(0); cin.tie(0); int x, y; while (cin >> x >> y) { if (x == 0) break; if (x > y) swap(x, y); cout << (canWin(x, y) ? 'T' : 'S') << '\n'; } return 0; }
Code mẫu của RR
#include <iostream> #include <algorithm> #define FOR(i,a,b) for(long i=a; i<=b; i++) using namespace std; long x,y; inline int get(long x,long y) { if (x>y) return get(y,x); if (x==y) return 0; if (y>= ((long long)x<<1) ) return 1; return 1-get(y%x,x); } int main() { scanf("%ld %ld",&x,&y); while (x || y) { if (get(x,y)) printf("T\n"); else printf("S\n"); scanf("%ld %ld",&x,&y); } return 0; }
Code mẫu của hieult
#include <stdio.h> //#include <conio.h> int main() { //freopen("NCOB.in","r",stdin); long long a,b; while(scanf("%lld %lld",&a,&b)>0 && a>0 && b>0) { int k = 0; long long r; while(true) { if(a==b) { k++; break; } if(a<b) { r = a; a = b; b = r; } if(a>2*b) break; else { a = a-b; k++; } } if(k%2==0) printf("T\n"); else printf("S\n"); } //getch(); }
Code mẫu của ll931110
#include <cmath> #include <iostream> using namespace std; int main() { double gold = (sqrt(5.0) + 1.0)/2.0; while (1) { int x,y; scanf("%d %d", &x, &y); if (!x && !y) break; if (x > y) swap(x,y); if (y >= gold * x) printf("T\n"); else printf("S\n"); }; };
Comments