codeforces 141 B. Hopscotch (规律)
2016-12-10 21:12
1586 查看
B. Hopscotch
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
output
input
output
input
output
input
output
input
output
题意:像小时候玩的跳格子,在一个直角坐标上,这里会有很多层,每层1 1 2 1 2 (重复1 2),给一个点,点在方格内且不压线,输出放个的序号
否则输出-1;
code:
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
int a,x,y;
scanf("%d%d%d",&a,&x,&y);
int b=y/a;//落在哪一行
b+=1;
if(y%a==0)
printf("-1\n");
else//行数奇偶分析,在分析x坐标
{
if(b==1)
{
if(2*x<a&&2*x>(-a))
printf("1\n");
else
printf("-1\n");
}
else if(b%2==0)
{
if(2*x<a&&2*x>(-a))
printf("%d\n",(b-2)/2*3+2);
else
printf("-1\n");
}
else if(b%2)
{
if(x<0&&x>(-a))
printf("%d\n",(b-1)/2*3);
else if(x>0&&x<a)
printf("%d\n",(b-1)/2*3+1);
else
printf("-1\n");
}
}
return 0;
}
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
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 1 2 1 2 (重复1 2),给一个点,点在方格内且不压线,输出放个的序号
否则输出-1;
code:
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
int a,x,y;
scanf("%d%d%d",&a,&x,&y);
int b=y/a;//落在哪一行
b+=1;
if(y%a==0)
printf("-1\n");
else//行数奇偶分析,在分析x坐标
{
if(b==1)
{
if(2*x<a&&2*x>(-a))
printf("1\n");
else
printf("-1\n");
}
else if(b%2==0)
{
if(2*x<a&&2*x>(-a))
printf("%d\n",(b-2)/2*3+2);
else
printf("-1\n");
}
else if(b%2)
{
if(x<0&&x>(-a))
printf("%d\n",(b-1)/2*3);
else if(x>0&&x<a)
printf("%d\n",(b-1)/2*3+1);
else
printf("-1\n");
}
}
return 0;
}
相关文章推荐
- codeforces-141【B找规律】【C思维】
- 【Codeforces 141 B Hopscotch 】+ 构造
- codeforces 141-B. Hopscotch(数学)
- CodeForces - 633B A Trivial Problem(找规律)
- CodeForces 554A-Kyoya and Photobooks【规律】
- CodeForces - 376C Divisible by Seven(数论:同余定理)(找规律)
- 【CodeForces 397B 】On Corruption and Numbers(规律)
- codeforces 24C 找规律
- Codeforces 796C Bank Hacking 贪心+规律
- CodeForces - 707C Pythagorean Triples(数学+规律)
- Codeforces 638A:Home Numbers(规律)
- CodeForces 550C Divisibility by Eight 简单题算是找规律?
- CodeForces - 668B Little Artem and Dance(规律题)
- Codeforces 949B A Leapfrog in the Array(数学,规律)
- codeforces 804A - Find Amir 贪心找规律
- codeforces 622D D. Optimal Number Permutation(找规律)
- Codeforces 622F 「数学数论」「数学规律」
- CodeForces-630 E. A rectangle【规律】
- CodeForces 558C Amr and Chemistry (位运算,数论,规律,枚举)
- Codeforces 396B On Sum of Fractions 规律题