码迷,mamicode.com
首页 > 其他好文 > 详细

Hopscotch(codeforces 141B)

时间:2019-10-13 17:22:28      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:return   data-   stand   required   byte   include   limit   put   length   

Hopscotch

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
Input
Copy
1 0 0
Output
Copy
-1
Input
Copy
3 1 1
Output
Copy
1
Input
Copy
3 0 10
Output
Copy
5
Input
Copy
3 0 7
Output
Copy
-1
Input
Copy
3 4 0
Output
Copy
-1
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    double a, x, y;
        scanf("%lf %lf %lf", &a, &x, &y);
        if(x>=a || x<=-a || !((int)y%(int)a)) puts("-1");
        else{
            int flr = (int)y/(int)a + 1;
            if(flr==1){
                if(x > -a/2 && x < a/2 && y > 0 && y < a) puts("1");
                else puts("-1");
            }else{
                int flag = 1;
                int num = (flr - 1) / 2 * 3 + 1;
                if((flr - 1) % 2 == 0) flag = 2;
                if(flag==1){
                    num++;
                    double up = flr * a, bot = up - a, lef = -a/2.0, rig = a/2.0;
                    if(y<up && y >bot && x>lef && x<rig) printf("%d\n", num);
                    else puts("-1");
                }else{
                    double up = flr * a, bot = up - a, lef1 = -a, rig1 = 0, lef2 = 0, rig2 = a;
                    if(y<up && y>bot && x>lef1 && x<rig1) printf("%d\n",num-1);
                    else if(y<up && y>bot && x>lef2 && x<rig2) printf("%d\n",num);
                    else puts("-1");
                }
            }
        }
    return 0;
}

 

Hopscotch(codeforces 141B)

标签:return   data-   stand   required   byte   include   limit   put   length   

原文地址:https://www.cnblogs.com/LS-Joze/p/11666779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!