题意是原本n个墓碑均匀分布在一个周长为10000的圆周上,现在加入m个,如果要使得n+m个墓碑都均匀分布的话,那么原来的墓碑最少的移动总距离是多少。
因为加入m个之后m+n个墓碑的位置是固定的,要是移动距离最少必定会有一个墓碑不动,将圆周分成m+n段,分别标上0,1,2,3,4。。然后需要移动的墓碑坐标就是数轴上面的非整数点,两边的值靠近哪个就选哪个,之后再等比例扩大即可。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
#include <cstdio>#include <cstring>#include <algorithm>using
namespace
std;int
main() { int
n,m; while(~scanf("%d%d",&n,&m)) { double
ans = 0; for(int
i = 1;i < n;i++) { double
pos = (double)i * (m + n) / n; ans += min(pos - (int)pos,(int)(pos + 1) - pos); } printf("%.4lf\n",ans * 10000 / (m + n)); } return
0;} |
原文:http://www.cnblogs.com/rolight/p/3538951.html