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 ...
随机推荐
- 微软职位内部推荐-SDEII_ ECO
微软近期Open的职位: SDE II SDE II Organization Summary: Engineering, Customer interactions & Online (EC ...
- CodeGenerator.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CiCe ...
- 华为acl(traffic-filter)和dhcp管理
华为alc配置实例:-traffic-filter # 在VLAN100上配置基于ACL的报文过滤,允许源IP地址为192.168.0.2/32的报文通过,丢弃其他报文. <HUAWEI> ...
- 【转】aspx与aspx.cs的关系
原文地址: http://www.cnblogs.com/axzxs2001/archive/2009/01/19/1378383.html 在vs中,有很多朋友问起,在一个网站项目中的aspx和as ...
- QTableView 一列添加两个按钮
在QTableView的一列里添加两个按钮,之前添加一个按钮的思路是一样的,只是计算了一下按钮的宽,放两个按钮而已. 添加一个按钮的例子:QTableView 添加按钮 本例源代码:QtTowButt ...
- SQLServer(MSSQL)、MySQL、SQLite、Access相互迁移转换工具 DB2DB v1.4
最近公司有一个项目,需要把原来的系统从 MSSQL 升迁到阿里云RDS(MySQL)上面.为便于测试,所以需要把原来系统的所有数据表以及测试数据转换到 MySQL 上面.在百度上找了很多方法,有通过微 ...
- ModernUI教程:使用WPF4.0
Modern UI 同时支持WPF4.0和4.5.下载包中包含了这两个版本的程序集.当你使用Nuget下载时,会根据你选择的运行时版本自动选择对应的版本下载.而Visual Studio2012的模板 ...
- SDRAM和dcfifo的联合
SDRAM和dcfifo的联合 设计原理 在"SDRAM突发读写页"实验中,留下了一个问题,就是从SDRAM读取数据的速度要与SDRAM的驱动时钟同步,这就造成了读出的数据的速率过 ...
- XMl各种格式转换功能代码
package com.cdv.test; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.File ...
- python2.7到python3代码转换脚本2to3的一些介绍
你的位置: Home ‣ Dive Into Python 3 ‣ 难度等级: ♦♦♦♦♦ 使用2to3将代码移植到Python 3 ❝ Life is pleasant. Death is ...