UVA1388 - Graveyard
2013-03-09 15:07
393 查看
[b]Graveyard[/b]
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!
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, and m -- the number of statues to be added (2View Code#include<stdio.h> #include<math.h> #define MAXSN 10000 double min(double a,double b) { return a<b?a:b; } int main(void) { int n,m,i,j,k; double ans,ave1,ave2,s1,s2; while(scanf("%d%d",&n,&m)!=EOF) { ans=0.0; ave1=(double)MAXSN/(n+m); ave2=(double)MAXSN/n; s1=ave1; s2=ave2; for(i=1; i<n; i++) { while(s1<=s2) s1+=ave1; ans+=min(s1-s2,s2-s1+ave1); s2+=ave2; } printf("%.4lf\n",ans); } return 0; }
相关文章推荐
- uva 1388 - Graveyard(思维)
- UVA之1388 - Graveyard
- UVA 1388 - Graveyard (推理,参考系)
- uva 1388 - Graveyard(思维)
- uva 1388 Graveyard
- uva1388 Graveyard
- UVA - 1388 Graveyard 【数学】
- UVa 1388 - Graveyard
- UVA 1388 Graveyard
- uva - UVA 1388 - Graveyard (数学推理)
- uva1388 Graveyard
- UVA-1388 - Graveyard-2014年4月20日021827
- uva 1388 - Graveyard
- UVA 1388 Graveyard
- uva 1388 - Graveyard(数论)
- uva1388 Graveyard
- uva1388 Graveyard
- uva 1388 - Graveyard(贪心)
- UVA - 1388 Graveyard 四舍五入
- uva 1388 - Graveyard