白书上的题,思路太特么牛逼了
将移动后的点标为 1,2,3.。。。N+M
可以知道未移动的点肯定有一个与移动后的点重合才能得到最小移动距离,令这个点与1重合,则能求出其他N-1个点的坐标
然后把这N-1个点移到离它最近的点即可
不懂可以画图看看
AC代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
int N, M;
double ans;
while( scanf( "%d%d", &N, &M ) != EOF ){
ans = 0.0;
for( int i = 1; i < N; i++ ){
double pos = (double) i / N * ( N + M );//求要移动点的坐标
ans += fabs( pos - (floor)( pos + 0.5 ) ) / ( N + M );//累加要移动的距离
}
printf( "%.4lf\n", ans * 10000 );//按比例放大
}
return 0;
}