CF 287(div 2) B Amr and Pins
解題思路:一開始自己想的是找出每一次旋轉(zhuǎn)所得到的圓心軌跡,將想要旋轉(zhuǎn)到的點代入該圓心軌跡的方程,如果相等,則跳出循環(huán),如果不相等,則接著進行下一次旋轉(zhuǎn)。后來看了題解,發(fā)現(xiàn),它的旋轉(zhuǎn)可以是任意角度的,所以旋轉(zhuǎn)后的圓心應(yīng)該在一個區(qū)域,而沒有固定的圓心軌跡的方程。
?
如圖所示,設(shè)c0為最初給出的圓,令圓c0繞O1點旋轉(zhuǎn),則對于繞O1點這一點的旋轉(zhuǎn)來說,c1為其旋轉(zhuǎn)后所得到的圓心軌跡,則可以看到,通過1次旋轉(zhuǎn)后,距離最近為0,距離最遠為線段OO2=2r,
對于第二次旋轉(zhuǎn),選取O2為圓心,作圓,再令圓c2繞O3旋轉(zhuǎn),得到圓心的軌跡為c3,離O點最近為OO2=2r,最遠為OO4=4r
所以推出一般結(jié)論,令想要旋轉(zhuǎn)到的點到起始的圓心的距離為d, 那么旋轉(zhuǎn)次數(shù)為d/2r,這里的四舍五入用進1法(不能舍去,所以用ceil函數(shù))
?
B. Amr and PinsAmr 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.
InputInput 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.
OutputOutput a single integer — minimum number of steps required to move the center of the circle to the destination point.
Sample test(s) input 2 0 0 0 4 output 1 input 1 1 1 4 4 output 3 input 4 5 6 5 6 output 0 NoteIn 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))); }
轉(zhuǎn)載于:https://www.cnblogs.com/wuyuewoniu/p/4252188.html
總結(jié)
以上是生活随笔為你收集整理的CF 287(div 2) B Amr and Pins的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: excel中打开乱码是怎么回事 Exce
- 下一篇: 如果去掉UITableView上的sec