[ACM_数学] LA 3708 Graveyard [墓地雕塑 圈上新加点 找规律]
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
Output
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 [墓地雕塑 圈上新加点 找规律]的更多相关文章
- LA 3708 Graveyard 墓地雕塑 NEERC 2006
在一个周长为 10000 的圆上等距分布着 n 个雕塑.现在又有 m 个新雕塑加入(位置可以随意摆放),希望所有 n + m 个雕塑能在圆周上均匀分布.这就需要移动一些原有的雕塑.要求 n 个雕塑移动 ...
- LA 3708 Graveyard(推理 参考系 中位数)
Graveyard Programming contests became so popular in the year 2397 that the governor of New Earck -- ...
- [ACM_模拟][ACM_数学] LA 2995 Image Is Everything [由6个视图计算立方体最大体积]
Description Your new company is building a robot that can hold small lightweight objects. The robo ...
- LA 3708 Graveyard
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&&如果可行必定最优&&非证明最优性)的题)(K)
例题4 墓地雕塑(Graveyard, NEERC 2006, LA 3708) 在一个周长为10000的圆上等距分布着n个雕塑.现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周 ...
- 墓地雕塑-LA3708
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=20& ...
- UVALive.3708 Graveyard (思维题)
UVALive.3708 Graveyard (思维题) 题意分析 这标题真悲伤,墓地. 在周长为1e4的圆周上等距分布着n个雕塑,现在要加入进来m个雕塑,最终还要使得这n+m个雕塑等距,那么原来的n ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- C/C++每日小练(七)——墓地雕塑
墓地雕塑 题目描写叙述: 在一个周长为10000的圆上等距分布着n个雕塑. 如今又有m个新雕塑增加(位置能够任意放).希望全部n+m个雕塑在圆周上均匀分布.这就须要移动当中一些原有的雕塑.要求n个雕塑 ...
随机推荐
- [转]linux /proc/cpuinfo 文件分析
在Linux系统中,提供了proc文件系统显示系统的软硬件信息.如果想了解系统中CPU的提供商和相关配置信息,则可以通过/proc/cpuinfo文件得到.本文章针对该文件进行简单的总结. 基于不同指 ...
- Factstone Benchmark
[问题描述] Amtel已经宣布,到2010年,它将发行128位计算机芯片:到2020年,它将发行256位计算机:等等,Amtel坚持每持续十年将其字大小翻一番的战略.(Amtel于2000年发行了6 ...
- ES 聚合函数
https://segmentfault.com/a/1190000004466154#articleHeader0 http://www.cnblogs.com/didda/p/5485681.ht ...
- 双机相关知识(原理、LVM、Raid技术)
1 双机知识 1.1 预备知识 1.1.1 基本概念 双机热备:双机热备双机管理软件可以根据心跳自动检测环境运行情况,如果发现一个节点挂掉了,会自动切换到另外一个 ...
- Spring aop——前置增强和后置增强 使用注解Aspect和非侵入式配置
AspectJ是一个面向切面的框架,它扩展了java语言,定义了AOP语法,能够在编译期提供代码的织入,所以它有一个专门的编译器用来生成遵守字节码字节编码规范的Class文件 确保使用jdk为5.0以 ...
- error C2065: 'INVALID_SET_FILE_POINTER' : undeclared identifier
Searching MSDN for that constant brings up one result: it's a failure code for SetFilePointer() and ...
- oracle系统表查询
oracle查询用户下的所有表 select * from all_tab_comments -- 查询所有用户的表,视图等select * from user_tab_comments -- 查询本 ...
- Points on cycle
Description There is a cycle with its center on the origin. Now give you a point on the cycle, you a ...
- img图片放大控件 lightbox.js
1.引入相关js,css jquery-1.7.2.min.js,lightbox.css,lightbox.js 2 图片增加<a href="大图片地址" rel=& ...
- bcb安装控件方法汇总
1.BCB 菜单: Project->Options->Packages->Add[喝小酒的网摘]http://blog.const.net.cn/a/8496.htm如果是BCB6 ...