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;
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值