Graveyard

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 1289   Accepted: 660   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

2 1
2 3
3 1
10 10

Sample Output

1666.6667
1000.0000
1666.6667
0.0000

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.

ps:http://poj.org/problem?id=3154

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std; double nmin(double x,double y)
{
return x<y?x:y;
}
int main()
{
int n,m,i,j;
double ans,s,o,temp;
double a[],c[];
while(scanf("%d%d",&n,&m)!=EOF)
{
s=1.0/(double)n;
o=1.0/(double)(n+m);
for(i=;i<n;i++)
a[i]=i*s;
for(j=;j<m+n;j++)
c[j]=j*o;
ans=;
for(i=;i<n;i++)
{
for(j=;j<m+n;j++)
{
if(a[i]<=c[j])
break;
}
int loc=j;
temp=fabs(a[i]-c[j]);
// printf("temp = %lf\n",temp);
if(loc>)
temp=nmin(temp,fabs(a[i]-c[loc-]));
if(loc<n+m-)
temp=nmin(temp,fabs(a[i]-c[loc+]));
ans+=temp;
} printf("%.4f\n",ans*);
}
return ;
}

然后下面是大神的代码:

#include<cstdio>
#include<cmath>
using namespace std; int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==)
{
double ans=;
for(int i=;i<n;i++)
{
double pos=(double)i/n*(n+m); //计算每个需要移动是雕塑的坐标
ans+=fabs(pos-floor(pos+0.5))/(n+m); //累加移动距离
}
printf("%.4f\n",ans*);//等比例扩大坐标
//第一次交是lf。。。结果就错了,可能是精度问题吧。
}
return ;
}

Graveyard(poj3154)的更多相关文章

  1. 1388 - Graveyard(数论)

    题目链接:1388 - Graveyard 题目大意:在一个周长为10000的圆形水池旁有n个等距离的雕塑,现在要再添加m个雕塑,为了使得n + m个雕塑等距离,需要移动一些雕塑,问如何使得移动的总位 ...

  2. 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&&如果可行必定最优&&非证明最优性)的题)(K)

    例题4  墓地雕塑(Graveyard, NEERC 2006, LA 3708) 在一个周长为10000的圆上等距分布着n个雕塑.现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周 ...

  3. [技术翻译]Guava-libraries(一): 用户指导

    用户指导 本文翻译自http://code.google.com/p/guava-libraries/wiki/GuavaExplained,由十八子将翻译,发表于博客园 http://www.cnb ...

  4. Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求

    上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...

  5. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  6. ASP.NET Core 之 Identity 入门(一)

    前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...

  7. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  8. Online Judge(OJ)搭建(第一版)

    搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...

  9. 如何一步一步用DDD设计一个电商网站(九)—— 小心陷入值对象持久化的坑

    阅读目录 前言 场景1的思考 场景2的思考 避坑方式 实践 结语 一.前言 在上一篇中(如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成),有一行注释的代码: public interfa ...

随机推荐

  1. 关于ASP.NET MVC4在IIS6中不认识安卓移动设备的解决办法

    在IIS7中发现安卓的手机浏览器是可以跳转滴. 项目中是采用***.mobile.cshtml来显示移动视图的. 部署到IIS6.0中发现并没有转到*.mobile.cshtml移动视图. 进过漫长的 ...

  2. 背水一战 Windows 10 (47) - 控件(ScrollViewer 特性): Chaining, Rail, Inertia, Snap, Zoom

    [源码下载] 背水一战 Windows 10 (47) - 控件(ScrollViewer 特性): Chaining, Rail, Inertia, Snap, Zoom 作者:webabcd 介绍 ...

  3. docker容器间跨主机通信

    http://jnzg905.iteye.com/blog/2269583 https://blog.csdn.net/pingpangbing0902/article/details/7823889 ...

  4. 简单的C# Socket通信实例

    一.套接字(socket)概念 套接字(socket)是通信的基石,是支持TCP/IP协议的网络通信的基本操作单元.它是网络通信过程中端点的抽象表示,包含进行网络通信必须的五种信息:连接使用的协议,本 ...

  5. [Ynoi2016]这是我自己的发明(莫队)

    话说这道题数据是不是都是链啊,我不手动扩栈就全 \(RE\)... 不过 \(A\) 了这题还是很爽的,通过昨晚到今天早上的奋斗,终于肝出了这题 其实楼上说的也差不多了,就是把区间拆掉然后莫队瞎搞 弱 ...

  6. ReactiveCocoa 源码阅读记录。

    1:RACSingle 需要订阅信号 RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACS ...

  7. JSX 和 template 随想

    就目前而言,我用到的前端页面开发框架主要有两种:以JSX为主的react和以template为主的vue. 虽然这两种方式各有千秋,但我其实更偏爱template多一些.为什么? 相较于灵活的JSX, ...

  8. Windows Phone开发手记-WinRT下分组拼音的实现

    Windows Phone版本号自升入8.1以来,开发者就多了一个选项,开发基于WinRT架构的WP或者Universal Windows App.然而开发框架转为WinRT后,很多原有的WP8基于S ...

  9. dubbo初学,快速体验

    本篇是基于spring框架的XML配置开发的dubbo应用程序,开发工具intellij idea,旨在对dubbo的快速理解和上手. 废话不多说,代码撸起来!!! 1.首先,新建一个maven工程, ...

  10. sql练习(针对Mysql)

    创建表: DROP TABLE DEPT; --部门表 CREATE TABLE DEPT( DEPTNO int PRIMARY KEY, DNAME ) , --部门名称 LOC ) ---部门地 ...