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

The input file contains several test cases, each of them consists of a a line that contains two integer numbers: n<tex2html_verbatim_mark> -- the number of holographic statues initially located at the ACM, and m<tex2html_verbatim_mark> -- the number of statues to be added (2n1000, 1m1000)<tex2html_verbatim_mark> . 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.

<tex2html_verbatim_mark>

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个塑像移动的总距离最小,输入n,m输出最小距离,小数点后4位。
解题思路:总是有一个雕塑没有移动,于是假设这个为原点,逆时针给n个点标号,表示到原点的距离【这里是比例距离】接下来我们把每个点移动到离它最近的距离,如果没有2个雕像移动到相同的位置,那么这样的移动一定是最优的。代码中,坐标为pos的雕塑移动的目的坐标位置是:floor(pos+0.5),就是四舍五入的结果。就是坐标缩小的好处。


 #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m){
double ans=0.0;
for(int i=;i<n;i++){
double pos=(double)i/n*(n+m);//计算每个需要移动的雕塑的坐标
ans+=fabs(pos-floor(pos+0.5))/(n+m);//累加移动距离
}
printf("%.4lf\n",ans*);//等比例放大
}return ;
}

[ACM_数学] LA 3708 Graveyard [墓地雕塑 圈上新加点 找规律]的更多相关文章

  1. LA 3708 Graveyard 墓地雕塑 NEERC 2006

    在一个周长为 10000 的圆上等距分布着 n 个雕塑.现在又有 m 个新雕塑加入(位置可以随意摆放),希望所有 n + m 个雕塑能在圆周上均匀分布.这就需要移动一些原有的雕塑.要求 n 个雕塑移动 ...

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

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

  3. [ACM_模拟][ACM_数学] LA 2995 Image Is Everything [由6个视图计算立方体最大体积]

    Description   Your new company is building a robot that can hold small lightweight objects. The robo ...

  4. LA 3708 Graveyard

    题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

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

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

  6. 墓地雕塑-LA3708

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=20& ...

  7. UVALive.3708 Graveyard (思维题)

    UVALive.3708 Graveyard (思维题) 题意分析 这标题真悲伤,墓地. 在周长为1e4的圆周上等距分布着n个雕塑,现在要加入进来m个雕塑,最终还要使得这n+m个雕塑等距,那么原来的n ...

  8. 思维 UVALive 3708 Graveyard

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

  9. C/C++每日小练(七)——墓地雕塑

    墓地雕塑 题目描写叙述: 在一个周长为10000的圆上等距分布着n个雕塑. 如今又有m个新雕塑增加(位置能够任意放).希望全部n+m个雕塑在圆周上均匀分布.这就须要移动当中一些原有的雕塑.要求n个雕塑 ...

随机推荐

  1. VBS 相关知识 笔记

    1.Option Explicit: 必须声明了变量之后才能赋值.  原话:语句在模块级别中使用,强制显式声明模块中的所有变量. w3scholl看到的内容: 变量声明 您可以使用 Dim.Publi ...

  2. B-F 字符串匹配算法

    Brute-Froce 算法是串的匹配模式算法中的一种其匹配方式如下: 1.设有字符串 a ,b;a为主串,在 a 中查找 b 串的位置 2.匹配方式如下: 2.1: 分别从 a,b串的第一个元素开始 ...

  3. (转)UVM内容梗概

    1. 类: 面向对象基础传统的面向对象编程与systemverilog类的特点,类的定义,成员与方法,构造函数,对象的复制和深/浅拷贝,父类/子类关系,类的继承,作用域的规则,对象的句柄以及赋值,方法 ...

  4. framebuffer应用编程实践

    framebuffer的使用主要包括4个部分: (1):首先需要打开设备文件 /dev/fb0. (2):获取设备的信息.包括可变信息和不可变信息,分别使用两个结构体来进行封装,这两个结构体在 < ...

  5. python语句表达式——黑板客老师课程学习

    1.赋值 多重赋值: a,b=1,2 a,b=’beijing’,’sh’ a,b=’bj’ a,b=(1,2) a,b=[1,2] …… 2.输入输出 输入: raw_input()   原始输入 ...

  6. Ubuntu下搭建Android编译环境

    Ubuntu一台新机器的一些环境搭建新增一个3TB的硬盘,挂载方法,大于2TB的得parted来进行分区1: sudo parted /dev/sda2: mklabel gpt3: unit TB4 ...

  7. Dev GridControl数据导出格式问题

    环境:DevExpress9.3,Vs2008 DevExpress的GridControl提供方便的数据导出到Excel功能,导出中用户可以根据GridControl的格式进行导出(ExportTo ...

  8. Eclipse 3.5使用dropins的插件安装方式

    以前安装Eclipse插件有两种方式 1 直接copy插件到features/plugins目录 2 在links目录下创建链接文件. 而 Eclipse 3.5又推出另一种新的安装途径, 更加灵活. ...

  9. 抓包工具Charles,anyproxy,mitmproxy等

    Charles:图形化界面,看着比较方便友好,也可以抓取https,不过电脑和手机都要下载证书,主要我的电脑上不能添加一添加就卡死 所以,抓取https的话,就用mitmproxy比较简单 1.安装C ...

  10. js 页面值变动监听

    1.初始化值map对象 var compareMap = {}:// 定义全局变量 function initCompareMap(context){//context 为指定要初始化的区域,即上下文 ...