CodeForces 141B Hopscotch(分类讨论)
来源:互联网 发布:魔兽世界 mac版 cruse 编辑:程序博客网 时间:2024/05/20 05:30
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.
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.
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 0 0
-1
3 1 1
1
3 0 10
5
3 0 7
-1
3 4 0
-1
题解:
给你正方形的摆法,告诉你正方形边长,和点的横纵坐标x,y,问你下落时会掉在哪个标号的方块里面,如果在边界或者没掉到上面就输出-1
思路:
分情况模拟,条理清楚就可以了
代码:
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>using namespace std;int main(){ double a,x,y,l1,r1,l2,r2; scanf("%lf%lf%lf",&a,&x,&y); if(x>-a&&x<a) { int p=y,d=a; if(p%d==0) printf("-1\n"); else if(p<2*d) { if(x>a/-2&&x<a/2) { if(p<d) printf("1\n"); else printf("2\n"); } else printf("-1\n"); } else { p-=2*d; int t=p/(2*d); p-=(t*2*d); if(p<d) { if(x==0) printf("-1\n"); else { printf("%d\n",2+t*3+(x<0?1:2)); } } else { if(x>a/-2&&x<a/2) printf("%d\n",2+t*3+3); else if(x<=a/-2||x>=a/2) printf("-1\n"); else printf("%d\n",2+t*3+(x<0?1:2)); } } } else printf("-1\n"); return 0;}
- CodeForces 141B Hopscotch(分类讨论)
- CodeForces 141B - Hopscotch
- CodeForces 141B Hopscotch
- CodeForces - 141B Hopscotch (模拟)水
- codeforces 141-B. Hopscotch(数学)
- 【Codeforces 141 B Hopscotch 】+ 构造
- codeforces 141 B. Hopscotch (规律)
- codeforces 789B(分类讨论)
- Codeforces 577B Module Sum(分类讨论)
- CodeForces 44B- A - Cola- 分类讨论
- Codeforces Problem 709B Checkpoints(分类讨论)
- Codeforces 2B The least round way 动态规划(分类讨论)
- Codeforces Round #371 (Div. 2) B. Filya and Homework(水题 分类讨论)
- Codeforces Problem 714B Filya and Homework(分类讨论)
- Codeforces 488B Candy Boxes【思维+分类讨论】
- Codeforces 560B Gerald is into Art【思维、分类讨论】
- Codeforces Round #101 (Div. 2) B. Hopscotch
- Codeforces R278 div2B 分类讨论
- MySQL 及 SQL 注入
- LaTeX简单入门
- 8.2 StringTokenizer类
- 其他IO流对象
- java面试题
- CodeForces 141B Hopscotch(分类讨论)
- WPF中使用cs代码设置附加属性的方式
- 贝叶斯网的推理模式
- STL工具库使用解析系列之一 STL::map
- Codeforces Round #448 (Div. 2): C. Square Subsets(线性基)
- 图像处理入门必看
- tinymce编辑器的高度随内容自动变化
- IM多点登录与消息漫游架构随想
- 计算机组成与设计(一)——计算机概要与技术