uva 1388 - Graveyard(思维)
来源:互联网 发布:网络安全管理系统软件 编辑:程序博客网 时间:2024/05/16 19:00
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
思路:把结果点N+M,扩展成距离为1的点,然后在找点原始N点离这些点的距离和最小。
#include<iostream>#include<cstring>#include<cstdio>#include<cmath>using namespace std;int n,m;double aabs(double x){ if(x<0)return -x; return x;}int main(){ while(~scanf("%d%d",&n,&m)) {double ans=0.0,num; for(int i=1;i<n;++i) { num=(double)i/n*(n+m); ans+=aabs(num-int(num+0.5))/(n+m);///因为距离为1所以最近距离就是离四色五入的最近整点距离 } ans*=10000.0; ///cout<<ans<<endl; printf("%.4lf\n",ans); }}
- uva 1388 - Graveyard(思维)
- UVA 3708 Graveyard(思维)
- uva 1388 - Graveyard
- Uva Oj 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
- UVA 1388 Graveyard
- UVA - 1388 Graveyard 【数学】
- uva 1388 - Graveyard(数论)
- UVA 1388 - Graveyard (推理,参考系)
- UVa 1388Graveyard 墓地雕塑
- 【linux 编程】linux/unix 进程的创建
- Linux录音详解
- DB2 生成数据库锁报告
- 数据基本类型,符合数据类型,数据结构的理解,抽象数据结构
- c++继承知识点积累:继承和构造函数
- uva 1388 - Graveyard(思维)
- ZOJ 1808 Immediate Decodability(trie)
- 修改Vendor FM VENDOR_UPDATE
- 带AI功能的3x3画井字游戏(引用版本)
- TCP建立和关闭的过程
- hdoj_1005 Number Sequence
- C语言预处理——宏定义
- 4MLinux 5.1 稳定版,迷你 Linux 发行版
- SQL语言总结 (1)