"Noi 2.7_2987" bunny picking up gold coins (algorithmic efficiency)

Source: Internet
Author: User

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&AMP;&AMP;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.