CodeForces 141B Hopscotch(分类讨论)

来源:互联网 发布:魔兽世界 mac版 cruse 编辑:程序博客网 时间:2024/05/20 05:30

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 strictlyinside 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,y,问你下落时会掉在哪个标号的方块里面,如果在边界或者没掉到上面就输出-1

思路:

分情况模拟,条理清楚就可以了

代码:

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>using namespace std;int main(){    double a,x,y,l1,r1,l2,r2;    scanf("%lf%lf%lf",&a,&x,&y);    if(x>-a&&x<a)    {        int p=y,d=a;        if(p%d==0)            printf("-1\n");        else if(p<2*d)        {            if(x>a/-2&&x<a/2)            {                if(p<d)                    printf("1\n");                else                    printf("2\n");            }            else                printf("-1\n");        }        else        {            p-=2*d;            int t=p/(2*d);            p-=(t*2*d);            if(p<d)            {                if(x==0)                    printf("-1\n");                else                {                    printf("%d\n",2+t*3+(x<0?1:2));                }            }            else            {                if(x>a/-2&&x<a/2)                    printf("%d\n",2+t*3+3);                else if(x<=a/-2||x>=a/2)                    printf("-1\n");                else                    printf("%d\n",2+t*3+(x<0?1:2));            }        }    }    else        printf("-1\n");    return 0;}


原创粉丝点击