CodeForces 141B Hopscotch

Posted Calm微笑

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 141B Hopscotch相关的知识,希望对你有一定的参考价值。

 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 strictlyinside 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
题意:给出如图所示的方块的排列方式,以及方块中的数字,已知方块的边长,给出横纵坐标,求该坐标方块的数字,若坐标在方块外部或者在方块边缘,输出-1.
模拟。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main()

	int a,x,y;
	while(scanf("%d%d%d",&a,&x,&y)!=EOF)
	
		if(y%a==0)
		
			printf("-1\\n");
			continue;
		
		int c=y/a;
		c=c+1;
		if(c==1)
		
			if(fabs(x*1.0)<a*1.0/2.0)
			   printf("1\\n");
			else printf("-1\\n");
		
		else
		
			if(c%2)
			
				int f=c/2*3;
				if(x==0)
				
					printf("-1\\n");
				
				else if(x<0)
				
					if(x<=-a)
					
						printf("-1\\n");
					
					else
					
						printf("%d\\n",f);
					
				
				else if(x>0)
				
					if(x>=a)
					
						printf("-1\\n");
					
					else
					
						printf("%d\\n",f+1);
					
				
			
			else
			
				if(fabs(x*1.0)>=(a*1.0/2.0))
				
					printf("-1\\n");
				
				else
				
					printf("%d\\n",(c+1)/2*3-1);
				
			
		
	
	return 0;


以上是关于CodeForces 141B Hopscotch的主要内容,如果未能解决你的问题,请参考以下文章

Hopscotch(codeforces 141B)

Codeforces 141B Hopscotch

codeforces上怎么看测试数据

如何看codeforces做了多少题

codeforces上怎么看测试数据

codeforces比赛后怎么看题解和答案