LA 3708 - Graveyard 墓地雕塑
来源:互联网 发布:直通车钻展淘宝客 编辑:程序博客网 时间:2024/06/09 16:52
点击打开链接
3708 - Graveyard
Time limit: 3.000 seconds
Programming contests became so popular in the year 2397 that the governor of New Earck -- the largest human-inhabited planet of the galaxy -- opened a special Alley of Contestant Memories (ACM) at the local graveyard. The ACM encircles a green park, and holds the holographic statues of famous contestants placed equidistantly along the park perimeter. The alley has to be renewed from time to time when a new group of memorials arrives.
When new memorials are added, the exact place for each can be selected arbitrarily along the ACM, but the equidistant disposition must be maintained by moving some of the old statues along the alley.
Surprisingly, humans are still quite superstitious in 24th century: the graveyard keepers believe the holograms are holding dead people souls, and thus always try to renew the ACM with minimal possible movements of existing statues (besides, the holographic equipment is very heavy). Statues are moved along the park perimeter. Your work is to find a renewal plan which minimizes the sum of travel distances of all statues. Installation of a new hologram adds no distance penalty, so choose the places for newcomers wisely!
Input
The input file contains several test cases, each of them consists of a a line that contains two integer numbers:n
-- the number of holographic statues initially located at the ACM, andm
-- the number of statues to be added (2n1000, 1m1000)
. The length of the alley along the park perimeter is exactly 10 000 feet.
Output
For each test case, write to the output a line with a single real number -- the minimal sum of travel distances of all statues (in feet). The answer must be precise to at least 4 digits after decimal point.
Pictures show the first three examples. Marked circles denote original statues, empty circles denote new equidistant places, arrows denote movement plans for existing statues.
Sample Input
2 1 2 3 3 1 10 10
Sample Output
1666.6667 1000.0 1666.6667 0.0
题意:在一个周长为10000的圆上等距分布着n个雕塑。现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周上均匀分布。这就需要移动其中一些原有的雕塑。要求n个雕塑移动的总距离最小。另其中一个雕塑不动,作为坐标原点,其他雕塑按照逆时针顺序标上到原点的距离标号。然后,我们把每个雕塑移动到离它最近的距离,如果没有两个雕塑移动到相同的位置,那么这样的移动一定是最优的。
#include<stdio.h>#include<math.h>int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { double ans=0; for(int i=1;i<n;i++) { double pos=(double)i/n*(n+m);//计算每个需要移动的雕塑的坐标 ans+=fabs(pos-floor(pos+0.5))/(n+m);//pos进行四舍五入 } printf("%.4lf\n",ans*10000); } return 0;}
- LA 3708 - Graveyard 墓地雕塑
- (LA 3708)墓地雕塑(Graveyard )
- 墓地雕塑(Graveyard, NEERC 2006, LA 3708)
- 墓地雕塑(Graveyard, NEERC 2006, LA 3708)
- 墓地雕塑(Graveyard, NEERC 2006, LA 3708)
- 墓地雕塑(LA 3708)
- UVaLive 3708 Graveyard 墓地雕塑
- LA 3708 Graveyard (墓地雕塑,给一个环 加入m个点后求原来的点最小
- Graveyard(墓地雕塑)
- LA3708 Graveyard 墓地雕塑
- graveyard,neerc(墓地雕塑)
- LA3708 Graveyard 墓地雕塑
- UVa 1388Graveyard 墓地雕塑
- LA3708 Graveyard 墓地雕塑-水题
- uvalive 3708 墓地雕塑
- 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&&如果可行必定最优&&非证明最优性)的题)(K)
- la 3708 Graveyard
- LA 3708- Graveyard
- anyevent::socket+anyevent::client 测试客户端
- Socket代理转发小记
- E - Triangle
- C语言函数指针基础
- hdu 4619
- LA 3708 - Graveyard 墓地雕塑
- POJ 3348 Cows 凸包+求多边形面积
- SQL Server MySQL Oracle
- 懂点经济学
- F - President's Office
- HDU 1063 (实数的乘法)
- uva424 (高精度加法)
- 程序员技术练级攻略
- 学生信息管理系统中系统登录问题