UVA LA3708 Graveyard

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

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 ≤ n ≤ 1000, 1 ≤ m ≤ 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.

Solution

1.刚开始我想无非就是选择一个点坐标不变,剩下的n-1个坐标每个移动 1 n − 1 n + m \frac{1}{n}-\frac{1}{n+m} n1n+m1 的距离。但最后看了答案之后发现是错的,毕竟不一定对应的点就是最近的坐标。

2.本题的核心就是保持一个点不变,剩下n-1个点找到与之最近的点。

3.我们可以将其看作为一个周长为n的圆,现在要把它变为周长为n+m的圆。计算那n-1个点的坐标在n+m的圆中的对应坐标 ,四舍五入找到与其最近的点(因为在n+m的圆中,n+m个点的坐标为1,2,……,n+m)。

4.对于情况3,不会出现两个点同时占同一个点的证明:在经过从n到n+m的转换后,坐标值无疑是变大的,而原坐标值之间的差分为1,经过转换后差分为 1 + m n > 1 1+\frac{m}{n} > 1 1+nm>1 。对于最坏的情况下,令x=1.5,y=2.499999999……,此时y-x还是小于1的,故不成立,故证明成立。

Code

#include <bits/stdc++.h>

#define MOD 1000000007

using namespace std;

int n,m;

void solve()
{
    double ans = 0.0;
    //计算n-1个点移动的距离
    for(int i=1; i<=n-1; i++)
    {
        //将n圆移动到n+m圆的新坐标
        double value = 1.0*i/n*(n+m);
		//新坐标与n+m圆上的坐标的差值
        double gap = fabs(floor(value+0.5)-value)/(n+m);
        //加到答案上
        ans += gap;

    }
	//记得乘回题目描述的10000圆
    printf("%.4lf\n", ans*10000);
}   

int main(void)
{
    while(scanf("%d%d",&n, &m) == 2)
        solve();

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于javaweb墓地管理系统,我可以为您提供一些介绍和演示。 墓地管理系统是一个用于管理和维护墓地信息的系统。它可以帮助管理者记录和查询墓地的基本信息,包括墓地位置、墓主人信息、墓地状态等。此外,墓地管理系统还可以提供一些额外的功能,如墓地预订、墓地维护、墓地费用管理等。 在JavaWeb开发中,可以使用Java语言和相关的技术来实现墓地管理系统。以下是一个简单的演示示例: 1. 数据库设计:首先,需要设计一个数据库来存储墓地信息。可以创建一个名为"graveyard"的数据库,并在其中创建一个名为"grave"的表,用于存储墓地信息。 2. 后端开发:使用Java语言和JavaWeb框架(如Spring MVC)来开发后端代码。可以创建一个名为"GraveController"的控制器类,用于处理墓地相关的请求。在该控制器中,可以实现一些方法,如添加墓地、查询墓地、修改墓地信息等。 3. 前端开发:使用HTML、CSS和JavaScript等前端技术来开发用户界面。可以创建一个名为"grave.jsp"的JSP页面,用于展示墓地信息和提供相关操作。在该页面中,可以使用表格来展示墓地列表,并提供一些按钮和表单来进行墓地的添加、查询和修改等操作。 4. 数据库连接:使用JDBC或者ORM框架(如MyBatis)来连接数据库,并实现数据的增删改查操作。可以在后端代码中编写相应的数据库连接和操作代码,以实现与数据库的交互。 5. 部署和测试:将开发好的代码部署到JavaWeb服务器(如Tomcat)上,并进行测试。可以通过访问相应的URL来测试墓地管理系统的功能,如添加墓地、查询墓地等。 这只是一个简单的示例,实际的墓地管理系统可能还涉及到其他功能和技术。希望这个演示能够帮助您对javaweb墓地管理系统有一个初步的了解。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值