您的位置:首页 > 其它

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!

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: