LA3708-Graveyard

来源:互联网 发布:淘宝卖家店铺动态设置 编辑:程序博客网 时间:2024/04/18 17:59

在周长为10000的圆上等距分布着n个雕塑,又要加入m个雕塑,希望所有雕塑均匀分布,问移动距离最小。
首先确定一个没动的雕塑位置为原点,然后通过坐标缩放计算需要移动的距离和。

#include <cstdio>#include <cmath>const int alley = 10000;int main(int argc, char const *argv[]) {    int n, m;    while (scanf("%d%d", &n, &m) == 2) {        double ans = 0.0;        for (int i = 1; i < n; i++) {            //坐标缩放            double pos = (double)(n + m) / n * i;            //pos四舍五入后的结果即为要移动的目标位置            ans += fabs(pos - floor(pos + 0.5)) / (n + m);        }        printf("%.4f\n", ans * alley);    }    return 0;}
0 0