UVA之1388 - Graveyard

简介:

1388 - Graveyard


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  (2$ \le$n$ \le$1000, 1$ \le$m$ \le$1000) . 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.

\epsfbox{p3708.eps}

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

【解析】




【代码】

/*********************************
*   日期:2013-11-25
*   作者:SJF0115
*   题号: 题目1388 - Graveyard
*   来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=446&page=show_problem&problem=4134
*   结果:AC
*   来源:UVA
*   总结:
**********************************/
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;


int main() {
    int i,n,m;
    while(scanf("%d %d",&n,&m) != EOF){
        double ans = 0.0;
        for(i = 1;i < n;i++){
            //计算每个需要移动的雕塑坐标
            double pos = (double)i / n * (n+m);
            //累加移动距离
            ans += fabs(pos - floor(pos+0.5))/(n+m);
        }
        printf("%.4lf\n",ans * 10000);
    }//while
    return 0;
}


目录
相关文章
|
设计模式 监控 Java
【设计模式】JAVA Design Patterns——Circuit Breaker(断路器模式)
【设计模式】JAVA Design Patterns——Circuit Breaker(断路器模式)
|
Unix Linux 开发工具
linux笔记 diff及patch的制作与使用
这篇文章是关于Linux系统中使用`diff`命令生成补丁文件以及使用`patch`命令应用这些补丁的详细教程和实战案例。
394 2
linux笔记 diff及patch的制作与使用
|
开发框架 前端开发 JavaScript
利用FastReport传递图片参数,在报表上展示签名信息
利用FastReport传递图片参数,在报表上展示签名信息
|
负载均衡
keepalived基础介绍
Keepalived是一个基于VRRP协议的软件,用于实现高可用的IPVS负载均衡服务,具备故障转移、健康检查和邮件通知等功能。
376 2
keepalived基础介绍
在Spring Boot中使用AOP实现日志切面
在Spring Boot中使用AOP实现日志切面
|
数据安全/隐私保护
BUU [HCTF 2018]admin
BUU [HCTF 2018]admin
121 0
|
机器学习/深度学习 数据采集 Python
机器学习模型的评估与选择标准
【6月更文挑战第1天】机器学习模型的评估至关重要,包括准确率、召回率、F1值和均方误差等指标。准确率衡量预测正确比例,召回率关注找出所有相关样本的能力,F1值是两者的综合。泛化能力同样重要,防止过拟合和欠拟合。不同场景可能侧重不同指标,如医疗诊断更关注召回率。选择模型需综合考虑多个因素,以实现最佳性能。通过实践和探索,我们可以更好地理解和优化模型评估,推动机器学习进步。
282 2
|
安全 JavaScript
json-bigin大数值问题详解
json-bigin大数值问题详解
1257 0
|
消息中间件 网络协议 Ubuntu
Ubuntu安装RabbitMQ server - 在外远程访问【内网穿透】
通过在ubuntu+cpolar+rabbitMQ环境下,实现mq服务端远程访问。
Ubuntu安装RabbitMQ server - 在外远程访问【内网穿透】
|
存储 IDE 开发工具
Python 教程之 Pandas(1)—— Pandas 数据框
Python 教程之 Pandas(1)—— Pandas 数据框
270 0