CodeForces 141B Hopscotch

简单题。

分情况算一下即可。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;

long long a,x,y;

int main()
{
    cin>>a>>x>>y;
    if(y%a==0)
    {
        printf("-1\n");
        return 0;
    }

    long long p = y/a +1;
    if(p==1)
    {
        if(x*2>-a&&x*2<a)
        {
            printf("1\n");
            return 0;
        }

        printf("-1\n");
        return 0;
    }

    if(p%2==0)
    {
        if(x*2>-a&&x*2<a)
        {
            printf("%d\n",(p/2-1)*3+2);
            return 0;
        }

        printf("-1\n");
        return 0;
    }

    else
    {
        if(x>-a&&x<0)
        {
            printf("%d\n",((p+1)/2-1)*3);
            return 0;
        }

        if(x>0&&x<a)
        {
            printf("%d\n",((p+1)/2-1)*3+1);
            return 0;
        }

        printf("-1\n");
        return 0;
    }

    return 0;
}

 

posted @ 2017-02-25 21:05  Fighting_Heart  阅读(202)  评论(0编辑  收藏  举报