LA3708 - Graveyard (等比缩放)

来源:互联网 发布:java pattern matcher 编辑:程序博客网 时间:2024/05/01 17:33

题意:
 周长为10000的圆,等距分布n个点,加入m个点后,求要使n+m等分布,所要移动的最小距离。
思路:
  等比缩放,将圆缩小为周长为n+m的圆

代码:

#include <iostream>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>using namespace std;int main(){int n, m;while (~scanf("%d%d", &n, &m) ) {int i;double t, ans = 0;for (i = 1; i <= n; i++)
{
t = (double)i / n*(n + m);//要移动的雕塑的坐标//*(m+n)为下面方便通分
ans += fabs(t - floor(t + 0.5)) / (n + m);//累计移动距离//四舍五入有bug
}printf("%.4lf\n", ans * 10000);}return 0;}

0 0