Title Link: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1185
Test instructions: Chinese question eh ~
Idea: Wythoff template problem, and 51nod1072 basically the same (http://www.cnblogs.com/geloutingyu/p/6198094.html), but the data is relatively large (1e18), there will be precision problems;
We can:
Order: Cnt=abs (x-y);
Geloutingyu=1e9;
a[3]={618033988, 749894848, 204586834} ((sqrt (5) +1)/2=1.618033988749894848204586834, we can first not calculate 1, and finally add a CNT on the good);
Pre=cnt/geloutingyu------1;
Las=cnt%geloutingyu-----2;
Gg=cnt+cnt*a[0]/geloutingyu+cnt*a[1]/mod/mod+cnt*a[2]/mod/mod/mod-----3;
United 1, 2 is cnt=pre*geloutingyu+las------4;
The 4 is then brought into the 3, with:
Gg=cnt+pre*a[0]+las*a[0]/mod+pre*a[1]/mod+las*a[1]/mod/mod+pre*a[2]/mod/mod+las*a[2]/mod/mod/mod----5;
We re-order: ans1=las*a[2], then there are:
Gg=cnt+pre*a[0]+las*a[0]/mod+pre*a[1]/mod+las*a[1]/mod/mod+pre*a[2]/mod/mod+ (ans1)/mod/mod/mod;
We re-order: Ans2=las*a[1]+pre*a[2]+ans1/mod, there are:
Gg=cnt+pre*a[0]+las*a[0]/mod+pre*a[1]/mod+ (ANS2)/mod/mod;
We re-order: Ans3=las*a[0]+pre*a[1]+ans2/mod, there are:
gg=cnt+pre*a[0]+ (ANS3)/mod;
So we just have to find out ans1, ANS2, ANS3 can solve the GG ...
Code:
1#include <bits/stdc++.h>2 #definell Long Long3 #defineGeloutingyu 10000000004 using namespacestd;5 6ll a[3]={618033988,749894848,204586834};7 8 intMainvoid){9 intT;Ten ll x, y; Onescanf"%d", &t); A while(t--){ -scanf"%lld%lld", &x, &y); - if(x>y) { the swap (x, y); - } -ll cnt=y-x; -ll Pre=cnt/geloutingyu, las=cnt%Geloutingyu; +ll ans1=las*a[2]; -ll ans2=pre*a[2]+las*a[1]+ans1/Geloutingyu; +ll ans3=pre*a[1]+las*a[0]+ans2/Geloutingyu; All gg=cnt+pre*a[0]+ans3/Geloutingyu; at if(gg==x) { -printf"b\n"); -}Else{ -printf"a\n"); - } - } in return 0; -}
51nod1185 (wythoff+ high precision)