Graveyard
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 1654   Accepted: 840   Special Judge

Description

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

Input file contains two integer numbers: n — the number of holographic statues initially located at the ACM, and m — the number of statues to be added (2 ≤ n ≤ 1000, 1 ≤ m ≤ 1000). The length of the alley along the park perimeter is exactly 10 000 feet.

Output

Write a single real number to the output file — the minimal sum of travel distances of all statues (in feet). The answer must be precise to at least 4 digits after decimal point.

Sample Input

sample input #1
2 1 sample input #2
2 3 sample input #3
3 1 sample input #4
10 10

Sample Output

sample output #1
1666.6667 sample output #2
1000.0 sample output #3
1666.6667 sample output #4
0.0

Hint

Pictures show the first three examples. Marked circles denote original statues, empty circles denote new equidistant places, arrows denote movement plans for existing statues.

Source

 

把所有的旧平分点移动到新平分点。贪心移动即可。

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int n,m;
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
double res=0.0;
for(int i=;i<n;i++){
double pos=(double)i/n*(n+m);
res+=fabs(pos- floor(pos+0.5))/(n+m);
}
printf("%.4f\n",res*);
}
return ;
}

POJ3154 Graveyard的更多相关文章

  1. 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&&如果可行必定最优&&非证明最优性)的题)(K)

    例题4  墓地雕塑(Graveyard, NEERC 2006, LA 3708) 在一个周长为10000的圆上等距分布着n个雕塑.现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周 ...

  2. Graveyard(poj3154)

    Graveyard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1289   Accepted: 660   Specia ...

  3. ural 1255. Graveyard of the Cosa Nostra

    1255. Graveyard of the Cosa Nostra Time limit: 1.0 secondMemory limit: 64 MB There is a custom among ...

  4. [ACM_数学] LA 3708 Graveyard [墓地雕塑 圈上新加点 找规律]

    Description   Programming contests became so popular in the year 2397 that the governor of New Earck ...

  5. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  6. LA 3708 Graveyard(推理 参考系 中位数)

    Graveyard Programming contests became so popular in the year 2397 that the governor of New Earck -- ...

  7. 1388 - Graveyard(数论)

    题目链接:1388 - Graveyard 题目大意:在一个周长为10000的圆形水池旁有n个等距离的雕塑,现在要再添加m个雕塑,为了使得n + m个雕塑等距离,需要移动一些雕塑,问如何使得移动的总位 ...

  8. POJ2100 Graveyard Design(尺取法)

    POJ2100 Graveyard Design 题目大意:给定一个数n,求出一段连续的正整数的平方和等于n的方案数,并输出这些方案,注意输出格式: 循环判断条件可以适当剪支,提高效率,(1^2+2^ ...

  9. poj 2100 Graveyard Design(尺取法)

    Description King George has recently decided that he would like to have a new design for the royal g ...

随机推荐

  1. jboss:在standalone.xml中设置系统属性(system-properties)

    就象在.net的web应用中,可以在web.config中设置appSettings一样,jboss的standalone.xml中也可以由开发人员自行添加系统属性,用法如下: </extens ...

  2. css3实践之图片轮播(Transform,Transition和Animation)

    楼主喜欢追求视觉上的享受,虽常以牺牲性能无法兼容为代价却也乐此不疲.本文就通过一个个的demo演示来简单了解下css3下的Transform,Transition和Animation. 本文需要实现效 ...

  3. 2016年优秀的java网站分享

    java中文网站 伯乐在线java版:http://www.importnew.com/ 码农网:http://www.codeceo.com/ infoq:http://www.infoq.com/ ...

  4. js时间倒计时

    看了网上的其他的例子,觉得写的都有点复杂,不好理解,于是自己动手写了个. 本来想封装成jquery插件,但是觉得因为功能很简单,没有必要做成jquery插件,引用的时候不需要引入jqery库,这里直接 ...

  5. DbEntry在Vs2012里的配置

    dbentry官方的版本还不支持vs2012,要再vs2012中使用,必须做下调整 1:新建类库项目,然后添加dbentry 的dll引用. 2:在建好的类库项目中.csproj 新添加了类库项目后, ...

  6. 将IList转换为List

     简单点说,IList<T>直接转换为List<T>可以不用考虑.IList<T>可以用至少2种方式简单的复制成List<T>:1.IList<T ...

  7. T4模板——一个神奇的代码生成器

    利用T4模板,可以很方便的从数据库映射成Model模型,相当于动软等功效.但动软是可以直接生成三层,抽象工厂的,T4没那么牛叉,所以我们一般只用作生成Modle或者Server等指定方法了. 废话少说 ...

  8. thinkphp 配置多数据库

    1配置文件中配置另一数据库连接信息 例如: 'TestModelConfig' => array( //'配置项'=>'配置值' 'DB_TYPE' => 'mysql', // 数 ...

  9. auto refresh iframe

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

  10. Beta冲刺---Day1

    站立式会议 站立式会议内容总结: 照片 老师是对的,其实无论在什么时候,都不会有一段很长很空闲的时间.比如说这个时候就还是有一大堆的作业.考试. 希望我们组员能够告别拖延症,然后再编码的时候全心地投入 ...