code forces Hopscotch (找規律)

So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2).

The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.

Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.

It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.

Input

The only input line contains three integers: axy, where a (1 ≤ a ≤ 100) is the side of the square, x and y ( - 106 ≤ x ≤ 106, 0 ≤ y ≤ 106) are coordinates of the stone.

Output

Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes.

Example
Input
1 0 0
Output
-1
Input
3 1 1
Output
1
Input
3 0 10
Output
5
Input
3 0 7
Output
-1
Input
3 4 0
Output
-1


【題解】

 就是思維靈活點  找規律,除了第一個,其他都是一個模型,我的做法是先打表,找出層數和每一層和該層第一個數之間的關係,然後判斷只有一個的層,這個只要x座標在a/2範圍內,直接用縱座標y/a,向上取整,就是該層的第一個數,輸出即可,然後是判斷一層兩個方塊的,可以發現,只要是一層兩塊的,它的第一個數都是3的倍數,所以y/a向上取整後的數如果能被3整除,就表示該層有兩個方塊,這時候再判斷一下橫座標x是不是0,0的話輸出-1,大於零的話就再加一(因爲一層有兩個的話,右邊的數比左邊的數大1),輸出即可。這樣就解出來了。


【AC代碼】

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

int a[1000005];
float m,n,k;

void f()
{
    a[1] = 1;
    int k=0;
    for(int i=2;i<=1000003;i+=2)
    {
        a[i]=i+k;
        a[i+1]=i+k+1;
        k++;
    }
}

int main()
{
    f();
    while(~scanf("%f%f%f",&k,&m,&n))
    {
         int tag = 0;
         if(fabs(m)<k/2)
         {
              if(ceil(n/k) != (int)n/k){
              int x = ceil(n/k);
              if(x==1 || x%2==0){
              int y = a[x];
              if(y%3==0 && m>0) y++;
              printf("%d\n",y);
              tag = 1;
              }
              else if(x%2==1&&m!=0){
                int y = a[x];
                if(y%3==0 && m>0) y++;
                printf("%d\n",y);
                tag = 1;
              }
              }
         }
         else if(fabs(m)<k&&m!=0)
         {
             if(ceil(n/k) != n/k){
             int x = ceil(n/k);
             int y = a[x];
             if(y%3==0)
             {
                 if(m>0) y++;
                 printf("%d\n",y);
                 tag=1;
             }
             }
         }
         if(!tag) printf("-1\n");
    }
    return 0;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章