Problem H
polygon
时限:1000ms 内存限制:10000K 总时限:3000ms
描述:
在一个周长为10000的圆上等距分布着n个点,即这n个点是一个正n边形的顶点。现在要另加m个点到圆上,新加的m个点可以任意选择位置(可以与原有的点重合)。然后将这n+m个点中的一些点延圆周移动,最终使n+m个点均匀分布,即在一个正n+m边形的顶点上。输出最小总移动距离。
输入:
输入两个整数 n, m。 (2≤n≤1000, 1≤m≤1000).
输出:
输出最小总移动距离,保留4位小数。
输入样例:
sample input #1 2 1
sample input #2 2 3
sample input #3 3 1
sample input #4 10 10
输出样例:
sample output #1 1666.6667
sample output #2 1000.0
sample output #3 1666.6667
sample output #4 0.0
图对应前3个样例
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int n, m;
double pos, ans;
while (cin >> n >> m) {
ans = 0;
for (int i = 0; i < n; i++) {
pos = (n + m) / (double)n * i;
ans = ans + fabs((int)(pos + 0.5) - pos);
}
printf("%.4f\n", ans * 10000 / (n + m));
}
return 0;
}