POJ3154 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的更多相关文章
- 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&&如果可行必定最优&&非证明最优性)的题)(K)
例题4 墓地雕塑(Graveyard, NEERC 2006, LA 3708) 在一个周长为10000的圆上等距分布着n个雕塑.现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周 ...
- Graveyard(poj3154)
Graveyard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1289 Accepted: 660 Specia ...
- 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 ...
- [ACM_数学] LA 3708 Graveyard [墓地雕塑 圈上新加点 找规律]
Description Programming contests became so popular in the year 2397 that the governor of New Earck ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- LA 3708 Graveyard(推理 参考系 中位数)
Graveyard Programming contests became so popular in the year 2397 that the governor of New Earck -- ...
- 1388 - Graveyard(数论)
题目链接:1388 - Graveyard 题目大意:在一个周长为10000的圆形水池旁有n个等距离的雕塑,现在要再添加m个雕塑,为了使得n + m个雕塑等距离,需要移动一些雕塑,问如何使得移动的总位 ...
- POJ2100 Graveyard Design(尺取法)
POJ2100 Graveyard Design 题目大意:给定一个数n,求出一段连续的正整数的平方和等于n的方案数,并输出这些方案,注意输出格式: 循环判断条件可以适当剪支,提高效率,(1^2+2^ ...
- poj 2100 Graveyard Design(尺取法)
Description King George has recently decided that he would like to have a new design for the royal g ...
随机推荐
- centos6 pyotp bug修复
yum install python-pip -ypip install pyotp vim /usr/lib/python2.6/site-packages/pyotp/utils.py... 49 ...
- Power of Two
Given an integer, write a function to determine if it is a power of two. bool isPowerOfTwo(int n) { ...
- VMware-Transport(VMDB) error -44:Message.The VMware Authorization Service is not running解决方案
出现的错误如下: 原因:本机中有一个VMware服务未开启导致的. 解决方案: 1.打开“运行”->输入services.msc !!!文章转自浩瀚先森博客,转载请注明,谢谢.http://ww ...
- 【BZOJ1003】【ZJOI2006】物流运输
1003: [ZJOI2006]物流运输trans Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2556 Solved: 1008[Submit] ...
- We Know What @You #Tag: Does the Dual Role Affect Hashtag Adoption-20160520
分析类的论文 1.Information publication:www2012 author: Mei qiao zhu 2.What 微博中的hashtag既可以表示谈论的内容,又可以代表一个群体 ...
- 《TCP/IP详解卷1:协议》第1章 概述-读书笔记
章节回顾: <TCP/IP详解卷1:协议>第1章 概述-读书笔记 <TCP/IP详解卷1:协议>第2章 链路层-读书笔记 <TCP/IP详解卷1:协议>第3章 IP ...
- 在eclipse中使用第三方库总结
一.建立user library 导入第三方jar文件,最简单的方式是:右键工程/属性/java build path/add external jars. 另一种方式是:window/prefren ...
- 转:PHP中防止SQL注入的方法
[一.在服务器端配置] 安全,PHP代码编写是一方面,PHP的配置更是非常关键. 我们php手手工安装的,php的默认配置文件在 /usr/local/apache2/conf/php.ini,我们最 ...
- strut2的拦截器之对request和session的封装
本文主要内容是对 implements Interceptor 这种方式的探索 前提是需要了解:责任链模式 对下面这句代码的理解: Map<String, Object> session ...
- $(document).ready()和window.onload的区别
来源于: The window.onload event fires when a document is completely downloaded to the browser. This mea ...