Test instructions: Ask the order of the Snake Palindrome's visit.
Solution: A very basic problem, first calculate the point of inquiry in the first few rings, and then use 4 while one after another to walk this lap. P.S. I've been trying to figure out how to use the while (), but I've been wa!. So use while () is both convenient and accurate, do not underestimate her.
P.p.s. KONJAC Konjac Brush DP Brush tired (do not do ~ (┬_┬)), then to do this problem, but time-consuming is not small ...
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5 using namespacestd;6 #defineN 100107 8 intN,x,y,xx,yy;9 Ten intMmin (intXintY) {returnX<y?x:y;} One intJudge () {return(X==XX&&Y==YY)?1:0;} A - intSolve () - { the intC=mmin (Mmin (x1, Y1), Mmin (n-x,n-y)), t=0; - inte=n-1; - for(intq=1; q<=c;q++) t+=4*e,e-=2; -xx=c+1, yy=C; + while(!judge () &&yy<n-c) yy++,t++; - while(!judge () &&xx<n-c) xx++,t++; + while(!judge () &&yy>c+1) yy--, t++; A while(!judge () &&xx>c+1) XX--, t++; at returnT; - } - - intMain () - { - intT; inscanf"%d%d",&t,&n); - while(t--) to { +scanf"%d%d",&x,&y); -printf"%d\n", Solve ()); the } * return 0
"Noi 2.7_2987" bunny picking up gold coins (algorithmic efficiency)