当前位置:   article > 正文

Hopscotch(思维)_hopscotchcsdn

hopscotchcsdn

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: a, x, y, 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

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
int main()
{
    int a,y,m,n,k,w;
    double x;
    while(~scanf("%d%lf%d",&a,&x,&y))
    {
        if(y%a==0)
            printf("-1\n");
        else
        {
            k=y/a;
            w=k/2;
            if(k==0)
            {
                if(a*0.5-fabs(x)>1e-3)
                    printf("1\n");
                else printf("-1\n");
            }
            else if(k&1)
            {
                m=1+w*3+1;
                if(a*0.5-fabs(x)>1e-3)
                    printf("%d\n",m);
                else printf("-1\n");
            }
            else
            {
                m=1+w*3;
                if(x<0&&a*1.0-fabs(x)>1e-3)
                    printf("%d\n",m-1);
                else if(x>0&&a*1.0-fabs(x)>1e-3)
                    printf("%d\n",m);
                else printf("-1\n");    
            }
        }
    }
    return 0; 
 } 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/722803
推荐阅读
  

闽ICP备14008679号