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)));
}
CF 287(div 2) B Amr and Pins的更多相关文章
- Codeforces Round #287 (Div. 2) B. Amr and Pins 水题
B. Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- codeforcfes Codeforces Round #287 (Div. 2) B. Amr and Pins
B. Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #287 (Div. 2) A. Amr and Music 水题
A. Amr and Music time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 贪心 Codeforces Round #287 (Div. 2) A. Amr and Music
题目传送门 /* 贪心水题 */ #include <cstdio> #include <algorithm> #include <iostream> #inclu ...
- CF Amr and Pins (数学)
Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
- CF #374 (Div. 2) C. Journey dp
1.CF #374 (Div. 2) C. Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...
随机推荐
- function——函数声明头的提升和预解析
函数: 即function语句的集合,就是将多个语句封装到一起: 函数的执行要会自己遍历,遇见函数 a():执行语句,就要移交控制权,函数执行完毕之后,控制权又移交回来了! 函数的参数要罗列在func ...
- <Android Framework 之路>Android5.1 Camera Framework(三)
上一次讲解了一下startPreview过程,主要是为了画出一条大致的从上到下的线条,今天我们看一下Camera在Framework的sendCommand和dataCallback,这部分属于衔接过 ...
- Fragment的理解
1.生命周期 启动Fragment时: onAttachonCreateonCreateViewonViewCreatedonActivityCreatedonStartonResume 启动后 ...
- 如何将App从一个账号迁移到另一个账号?
App迁移(App transfer):将App从一个开发者账号迁移至另一个开发者账号.此文演示了整个迁移过程,为了方便解释,在此过程中,将App转出的开发者账号我们下文将会称之为A账号,接收杭州Ap ...
- 用一个小的例子来说明为什么TCP采用三次握手才能保证连接成功
关于TCP的三次握手,有很多朋友还在疑惑为什么是三次,而不是两次,LZ想了一下用一个例子来说明最好. 场景: 办公室有一名前台(服务器),若干业务员(fork出来的进程) 客户(客户端) 为什么我 ...
- Java基础——过滤器和监听器
什么是过滤器? Servlet过滤器和Servlet十分相似,但它具有拦截客户端请求的功能,Servlet过滤器可以改变请求中的内容,来满足实际开发中的需要.对于开发人员而言,过滤器实际上就是在Web ...
- input的radio根据value和name反向显示
1.获取radio的值,是根据name设置一组单选框. 例如: <div id="sexBox"> <input type="radio" i ...
- 洛谷1099 [NOIP2007] 树网的核
链接https://www.luogu.org/problemnew/show/P1099 题目描述 设T=(V,E,W)是一个无圈且连通的无向图(也称为无根树),每条边到有正整数的权,我们称TTT为 ...
- django-10-中间件和上下文管理器
<<<中间件的引入>>> 用户<->中间件<->url->视图 在app目录里面 middleware.py (1)中间件就是一个 ...
- [luogu] P4040 [AHOI2014/JSOI2014]宅男计划(贪心)
P4040 [AHOI2014/JSOI2014]宅男计划 题目背景 自从迷上了拼图,JYY就变成了个彻底的宅男.为了解决温饱问题,JYY不得不依靠叫外卖来维持生计. 题目描述 外卖店一共有N种食物, ...