惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
A
About on SuperTechFans
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
博客园 - 聂微东
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
量子位
博客园 - 三生石上(FineUI控件)
Recent Announcements
Recent Announcements
The GitHub Blog
The GitHub Blog
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

OhYee 博客

小鹏辅助驾驶测评|OhYee 博客 小鹏非支持手机开启自动解锁|OhYee 博客 使用函数计算实现 301 重定向|OhYee 博客 针对 HTML 内容使用 Ant Design 图片弹框|OhYee 博客 博客进程泄露及僵尸进程解决|OhYee 博客 蓝易云服务器体验|OhYee 博客 SSH 调起本地 VSCode|OhYee 博客 【2022 秋招内推】阿里云后端研发工程师|OhYee 博客 使用函数计算获取 IP 地址信息|OhYee 博客 正确获取客户端 IP/HTTP Header 也可能重复|OhYee 博客 评测 Oculus Quest2 及 BigScreen|OhYee 博客 NextJS 热重载保留状态|OhYee 博客 如何优雅地贴 gist 代码|OhYee 博客 Linux 精细化文件权限|OhYee 博客 VSCode 容器开发环境|OhYee 博客 Clash 的不兼容更新排查|OhYee 博客 Zeek 导出 PCAP|OhYee 博客 记一次 ssh 配置问题|OhYee 博客 Git Commit 规范化工具|OhYee 博客 谈谈《星之卡比-探索发现》|OhYee 博客 VSCode 快捷键绑定 Shell 命令|OhYee 博客 ASN.1 语法及 X.509 证书格式解析解析|OhYee 博客 腾讯企业邮箱忽略 MX 记录发信|OhYee 博客 Chrome/Edge 标签组插件|OhYee 博客 【应届内推】阿里云后端研发工程师|OhYee 博客 损坏的 Typecho 备份处理为 JSON|OhYee 博客 VS Code VIM 插件高效使用|OhYee 博客 SSH 正反向代理|OhYee 博客 Let's Encrypt 根证书过期引发的问题|OhYee 博客 OpenWRT 忽略内核依赖|OhYee 博客
Uva 1388.Graveyard|OhYee 博客
2016-08-22 · via OhYee 博客

这是一篇最后编辑于 8 年前 的文章,其内容可能与目前实际情况差异较大,请注意甄别

题目

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

题解

原本有 n 个东西在圆周上平均分配,再多 m 个, 求最少需要移动的距离

画下图很容易找到关系
将最上面当作原点,所有点从原点开始按间距摆放

每个点应该移动到与其最接近的点上,由于平均分配,并且是增加数量,因此新的图里,点会更加密集,这就保证了不会有有一个新位置同时是两个老位置的最近位置

只需要找到每个位置最近的新位置即可

最需要注意的是 double 造成的各种 浮点误差

结果最少输出 4 位精度,输出 6 位小数妥妥的

代码

/*
By:OhYee
Github:OhYee
Blog:http://www.oyohyee.com/
Email:oyohyee@oyohyee.com

かしこいかわいい?
エリーチカ!
要写出来Хорошо的代码哦~
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <bitset>
#include <functional>

using namespace std;

const double eps = 1e-6;
const double l = 10000;

bool equal(double a,double b) {
    return fabs(a - b) < eps;
}
int toInt(double a) {
    return (int)(a + 0.001);
}

bool Do() {
    double n,m;
    if(!(cin >> n >> m))
        return false;

    m += n;

    double per = l / n;
    double newper = l / m;

    double ans = 0;
    for(int i = 0;i < n;i++) {
        double pos = i * per;
        double newpos = pos / newper;
        if(!equal(newpos,(double)(toInt(newpos)))) {
            int a = toInt(newpos);
            ans += min(fabs(pos - a*newper),fabs(pos - (a + 1)*newper));
        }
    }

    cout << fixed << setprecision(6) << ans << endl;
    return true;
}

int main() {
    while(Do());
    return 0;
}