NEERC 2006 / UVa 1388 Graveyard (数学&想法题&找最近整数)
来源:互联网 发布:ubuntu wily 源 编辑:程序博客网 时间:2024/06/03 19:50
1388 - Graveyard
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=4134
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 (2n1000, 1m1000) . 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.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
给移动之后的点标上坐标序号,然后求移动之前的点的坐标到最近坐标的最小距离和。
体会下面计算k这个值的好处。
完整代码:
/*0.009s*/#include<cstdio>#include<cmath>int main(void){double n, m;while (~scanf("%lf%lf", &n, &m)){double k = 1.0 + m / n, ans = 0.0;for (int i = 1; i < n; ++i) //第一个(标号为0)不用移动{double pos = k * i;ans += fabs(pos - round(pos));}printf("%.4f\n", ans * 10000 / (n + m));}return 0;}
- NEERC 2006 / UVa 1388 Graveyard (数学&想法题&找最近整数)
- UVA - 1388 Graveyard 【数学】
- uva - UVA 1388 - Graveyard (数学推理)
- Uva 1388 Graveyard 解题报告(数学)
- LA 3708 Graveyard,NEERC 2006
- Graveyard NEERC 2006,LA 3708 By ACReaper
- uva 1388 - Graveyard
- Uva Oj 1388 - Graveyard
- uva 1388 - Graveyard(思维)
- UVa 1388 - Graveyard
- uva 1388Graveyard
- uva 1388 - Graveyard(贪心)
- UVA之1388 - Graveyard
- Uva 1388 Graveyard - 水题
- UVA 1388 Graveyard
- UVA - 1388 Graveyard 四舍五入
- UVA 1388 - Graveyard
- UVA - 1388 Graveyard
- 线性同余和扩展欧几里得的运用小结
- SPOJ8222(后缀自动机--出现次数最多的子串)
- Ubuntu 12.04 改造指南
- leetcode simplify path
- IREPORT 标签式报表
- NEERC 2006 / UVa 1388 Graveyard (数学&想法题&找最近整数)
- Linux12samba软件包
- 在Centos下使用英伟达GPU,文本模式下发现分辨率不能修改的方法
- UVA 10494 If We Were a Child Again
- 黑马程序员————高新技术————动态代理
- POJ-2342 Anniversary party(Tree dp)
- Windows 同时安装python2 和python3,并设置不同的右键关联
- 在Ubuntu下安装配置Samba服务
- K-means学习笔记