CodeForces 141B - Hopscotch

B. 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: 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.

Sample test(s)
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


===============================

除了1号格子以外其他的都是1-2循环


#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    int a,x,y,ans;
    cin>>a>>x>>y;
    if(x>=a||x<=-a||y%a==0||y<=0) cout<<"-1"<<endl;
    else if(x<(a+1)/2&&x>-((a+1)/2)&&y<a) cout<<"1"<<endl;
    else
    {
        y-=a;
        if((y/a+1)%2)
        {
            if(x<(a+1)/2&&x>-((a+1)/2))
            {
                ans=y/a/2*3+2;
                cout<<ans<<endl;
            }
            else cout<<"-1"<<endl;
        }
        else
        {
            if(x>0)
            {
                ans=(y/a+1)/2*3+1;
                cout<<ans<<endl;
            }
            else if(x<0)
            {
                ans=(y/a+1)/2*3;
                cout<<ans<<endl;
            }
            else cout<<"-1"<<endl;
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值