CF141B Hopscotch 题解

Hopscotch

题面翻译

n n n 个形状和大小都一致的正方体积木,积木堆积的样式是第一层只有一个正方体,然后上面就开始循环了,循环体为:第一层是一个正方体,第二层是两个正方体。如下图所示:

现在给你三个数 a , x , y a,x,y a,x,y 表示正方体的边长,然后让你输出坐标 ( x , y ) (x,y) (x,y) 对应的数。如果在积木的边界上或者是不在正方体上输出 − 1 -1 1

题目描述

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.

输入格式

The only input line contains three integers: $ a $ , $ x $ , $ y $ , where $ a $ ( $ 1<=a<=100 $ ) is the side of the square, $ x $ and $ y $ ( $ -10{6}<=x<=10{6},0<=y<=10^{6} $ ) are coordinates of the stone.

输出格式

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.

样例 #1

样例输入 #1

1 0 0

样例输出 #1

-1

样例 #2

样例输入 #2

3 1 1

样例输出 #2

1

样例 #3

样例输入 #3

3 0 10

样例输出 #3

5

样例 #4

样例输入 #4

3 0 7

样例输出 #4

-1

样例 #5

样例输入 #5

3 4 0

样例输出 #5

-1
#include<iostream>
using namespace std;
int a,x,y;//定义三个正整数,一个叫a……
int _main(){
	if(y%a==0)return-1;
	if(y<0)return-1;
	if(abs(x)>=a)return-1;
	//以上为一开始讨论的三种不可能情况
	int c=y/a;
	if(c==0||c%2){
		if(abs(2*x)>=a)return-1;
		else return max(1,(c+1)/2*3-1);
	}
	//以上为第0层或者奇数层的情况
	if(c&&c%2==0){
		if(x==0)return-1;
		else return c/2*3+(x+a)/a;
	}
	//以上为非零偶数层的情况
}
int main(){
	cin>>a>>x>>y;
	cout<<_main();
}
  • 12
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只贴代码君

帅帅的你,留下你的支持吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值