CF 287(div 2) B Amr and Pins
解题思路:一开始自己想的是找出每一次旋转所得到的圆心轨迹,将想要旋转到的点代入该圆心轨迹的方程,如果相等,则跳出循环,如果不相等,则接着进行下一次旋转。后来看了题解,发现,它的旋转可以是任意角度的,所以旋转后的圆心应该在一个区域,而没有固定的圆心轨迹的方程。
如图所示,设c0为最初给出的圆,令圆c0绕O1点旋转,则对于绕O1点这一点的旋转来说,c1为其旋转后所得到的圆心轨迹,则可以看到,通过1次旋转后,距离最近为0,距离最远为线段OO2=2r,
对于第二次旋转,选取O2为圆心,作圆,再令圆c2绕O3旋转,得到圆心的轨迹为c3,离O点最近为OO2=2r,最远为OO4=4r
所以推出一般结论,令想要旋转到的点到起始的圆心的距离为d, 那么旋转次数为d/2r,这里的四舍五入用进1法(不能舍去,所以用ceil函数)
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 105, - 105 ≤ x, y, x', y' ≤ 105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
2 0 0 0 4
1
1 1 1 4 4
3
4 5 6 5 6
0
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
#include<stdio.h>
#include<math.h>
int main()
{
double i,r,x0,y0,x1,y1;
scanf("%lf %lf %lf %lf %lf",&r,&x0,&y0,&x1,&y1);
double dist=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
printf("%.0lf\n",ceil(dist/(2*r)));
}
最新文章
- Xtrabackup原理及使用innobackupex进行MySQL数据库备份恢复
- api接口类型
- Nginx php-fpm php mysql
- python文件和元组
- 使用WebView视图显示网页-----迷你浏览器
- Spring事务传递性探讨
- 自然语言.例如:求n!。
- minSdkVersion与targetSdkVersion
- [iOS、Unity、Android] 浅谈闭包的使用方法
- TCP/IP 协议栈 -- 编写UDP客户端注意细节
- 针对Chrome谷歌等浏览器不再支持showModalDialog的解决方案
- 学习笔记:Zookeeper选举机制
- git常用笔记整理
- 换工作之后需要兼容ie8的我
- 2554 ACM 杭电 数学
- Android 自定义ImageView支持缩放,拖拽,方便复用
- 6-1 平衡的括号 uva673
- hadoop2.2.0 centos 编译安装详解
- Android Studio OkHttpClient使用
- e559. 创建窗口