Graveyard NEERC 2006,LA 3708 By ACReaper
#include <cstdio> #include <cmath> using namespace std; int main(){ int n,m; while(scanf("%d%d",&n,&m) == 2){ double 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); //算出的是移动的距离占整段的大小,然后累加,注意整段大小是m + n对应10000 } printf("%.4lf\n",ans * 10000); } return 0; }
解释我已经注释的很清楚了,太妙了这题!
2013 05 06
By ACReaper