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
1 0 0
-1
3 1 1
1
3 0 10
5
3 0 7
-1
3 4 0
-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 == ){
puts("-1");
continue;
}
if(y == ){
puts("-1");
continue;
}
if(t == || t == ){
if(fabs(cx) >= 0.5)
puts("-1");
else
printf("%d\n", t);
continue;
}
// printf("t = %d\n", t);
if(t % == ){
if(fabs(cx) >= 0.5){
puts("-1");
}
else
printf("%d\n", t + t/ - );
}
else{
if(fabs(cx) >= || x == ){
puts("-1");
}
else{
if(cx < )
printf("%d\n", (t - ) + (t - )/);
else
printf("%d\n", (t - ) + (t - )/ + );
}
}
}
return ;
}
Hopscotch(细节)的更多相关文章
- River Hopscotch POJ - 3258
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...
- 【洛谷】2990:[USACO10OPEN]牛跳房子Cow Hopscotch【单调队列优化DP】
P2990 [USACO10OPEN]牛跳房子Cow Hopscotch 题目描述 The cows have reverted to their childhood and are playing ...
- Vue.js 和 MVVM 小细节
MVVM 是Model-View-ViewModel 的缩写,它是一种基于前端开发的架构模式,其核心是提供对View 和 ViewModel 的双向数据绑定,这使得ViewModel 的状态改变可以自 ...
- vue2.0实践的一些细节
最近用vue2.0做了个活动.做完了回头发现,好像并没有太多的技术难点,而自己好像又做了比较久...只能说效率有待提升啊...简单总结了一些比较细节的点. 1.对于一些已知肯定会有数据的模块,先用一个 ...
- 深入理解JS 执行细节
javascript从定义到执行,JS引擎在实现层做了很多初始化工作,因此在学习JS引擎工作机制之前,我们需要引入几个相关的概念:执行环境栈.全局对象.执行环境.变量对象.活动对象.作用域和作用域链等 ...
- javaScript中的小细节-script标签中的预解析
首先介绍预解析,虽然预解析字面意思很好理解,但是却是出坑出的最多的地方,也是bug经常会有的地方,利用好预解析的特性可以解决很多问题,并且提高代码的质量及数量,浏览器在解析代码前会把变量的声明和函数( ...
- 分享MSSQL、MySql、Oracle的大数据批量导入方法及编程手法细节
1:MSSQL SQL语法篇: BULK INSERT [ database_name . [ schema_name ] . | schema_name . ] [ table_name | vie ...
- Android ScrollView监听滑动到顶部和底部的两种方式(你可能不知道的细节)
Android ScrollView监听滑动到顶部和底部,虽然网上很多资料都有说,但是不全,而且有些细节没说清楚 使用场景: 1. 做一些复杂动画的时候,需要动态判断当前的ScrollView是否滚动 ...
- [更新设计]跨平台物联网通讯框架ServerSuperIO 2.0 ,功能、BUG、细节说明,以及升级思考过程!
注:ServerSuperIO 2.0 还没有提交到开源社区,在内部测试!!! 1. ServerSuperIO(SSIO)说明 SSIO是基于早期工业现场300波特率通讯传输应用场景发展.演化而来. ...
随机推荐
- Laravel 4 Blade模板引擎
http://my.oschina.net/5say/blog/201290 模板输出 基本输出 1 <!-- app/views/example.blade.php --> 2 < ...
- [Redux] Passing the Store Down with <Provider> from React Redux
Previously, we wrote the Provider component by ourself: class Provider extends Component { getChildC ...
- 慕课linux学习笔记(一)centOS的安装
在VMware8上安装centos6.3 准备的文件 新建虚拟机 选择新建一个空的虚拟机 选择linux和centos 分配20G的硬盘空间 ' 修改配置 调整内存空间 桥接:虚拟机和真实机通讯使用的 ...
- Javascript基础form表单
<!DOCTYPE HTML> <html> <head> <script type="text/javascript" charset= ...
- 关于css3的rgba
在rgba之前,我们应该知道rgb.它就是红色R+绿色G+蓝色B.那rgba是什么?简单的说就是在rgb的基础之上加上一个通道alpha.他的语法如下: r 红色值.正整数(0~255) | 百 ...
- 开源项目Material Calendar View 学习记录 (一)
开源项目Material Calendar View 学习记录 Github: https://github.com/prolificinteractive/material-calendarview ...
- NSDictionary使用小结
http://blog.csdn.net/ms2146/article/details/8656787
- 一个经试用效果非常不错的数据库连接池--JAVA
前言: 虽说现在许多企业级的应用服务器均自己带有数据库连接池功能,就连 Tomcat 也支持了这种功能.然而在许多时候,我们还是要使用数据库连接池,如:访问数据库的 Java 桌面应用程序等.这个数据 ...
- php统计文件夹大小
function dirsize($dir){ @$dh = opendir($dir); $size = 0; while($file = @readdir($dh)){ if($file!=&qu ...
- sql 删除两条完全相同的记录
delete a from ( select *,ps=row_number()over(PARTITION by cCaption order by getdate()) from AA_Colu ...