Uva--10161--ant on a chessboard

Source: Internet
Author: User

It's a simple math problem, but it takes some time to find out the rules.

My idea is: to find the coordinates of 3 points for each basic graph and the relationship between the time, and then the other points are classified by these 3 points to discuss the results

The code is as follows:

#include <iostream>
#include <cmath>
using namespace std;

int main ()
{
    int n,x,y,a,b,i,sn,n;
    while (Cin>>n&&n)
    {
         double m=n;
         N= (sqrt ((double) m)-1)/2; 
         sn=4*n*n+4*n+1;
         a=4*n*n+6*n+3;
         b=4*n*n+10*n+7;
         if (sn==n)
         {
            y=2*n+1;
            x=1;
         }
         else if (n<=a)
         {
            x=2*n+2-(a-n);
            y=2*n+2;
         } 
         else if ((4*n*n+8*n+4) >=n)
         {
              x=2*n+2;
              y=1+ (4*n*n+8*n+4-n);
         }
         else if (n<=b)
         {
              x=2*n+2+1;
              y=2*n+3-(b-n);
         }
         else
         {
            x=2*n+3+ (b-n);
            y=2*n+3;
         }
         cout<<x<< "" <<y<<endl;
    }
  return 0;
}


Related Article

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.