• Hopscotch(细节)


     Hopscotch
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    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.

    Sample Input

    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;注意边界的考虑;输出三个数代表正方形变长,以及石子坐标;
    代码:
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<stack>
    #include<set>
    using namespace std;
    
    int main(){
        int a, x, y;
        while(~scanf("%d%d%d", &a, &x, &y)){
            double cx = 1.0 * x /a, cy = 1.0 * y/a;
            int t = (int)(cy + 0.999999999999999);
            if(y % a == 0){
                puts("-1");
                continue;
            }
            if(y == 0){
                puts("-1");
                continue;
            }
            if(t == 1 || t == 2){
                if(fabs(cx) >= 0.5)
                    puts("-1");
                else
                    printf("%d
    ", t);
                    continue;
            }
        //    printf("t = %d
    ", t);
            if(t % 2 == 0){
                if(fabs(cx) >= 0.5){
                    puts("-1");
                }
                else
                    printf("%d
    ", t + t/2 - 1);
            }
            else{
                if(fabs(cx) >= 1 || x == 0){
                    puts("-1");
                }
                else{
                    if(cx < 0)
                        printf("%d
    ", (t - 1) + (t - 1)/2);
                    else
                        printf("%d
    ", (t - 1) + (t - 1)/2 + 1);
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    .html(),.text()和.val()的差异
    jQuery选取表单元素
    jquery中动画特效方法
    js正则函数match、exec、test、search、replace、split使用介绍集合
    关于LDA的几何表示——MATLAB实现
    关于PCA的几何表示——MATLAB实现
    简单的线性分类——MATLAB,python3实现
    关于KNN的python3实现
    拔靴法--Bootstrap--R语言实现
    Poisson Distribution——泊松分布
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5483816.html
Copyright © 2020-2023  润新知