UVALive - 3708 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 ≤ 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.
Note: 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

白书解释:为什么不会有两个雕塑移动到一个相同的位置?因为一开始认为周长是m+n,只有n个雕塑,长度是一定会大于一的。而想出现两个雕塑到同一个坑的情况,只有是0.5,1.4999.....类似这样的两个雕塑距离为一的情况,这种情况不可能存在。

#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
    int n,m;
    double pos,ans;
    while(~scanf("%d%d",&n,&m))
    {
        ans=0.0;
        for(int i=1;i<n;i++)
        {
            pos=(double)(n+m)/n*i;
            ans+=fabs(pos-floor(pos+0.5))/(n+m);
        }
        printf("%.4lf\n",ans*10000);
    }
}

 

  • 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、付费专栏及课程。

余额充值