N sculptures are evenly distributed on a circle with a circumference of 10000. Now m sculptures are added to the circle at random, and n + m sculptures are still evenly distributed. This requires moving some of the statues to find the minimum distance of movement.
Method: this is still the example of LIU Da. Assume that a statue does not move and serves as the coordinate origin. The distance from the other statue to the origin is counter-clockwise. Not the actual distance, but the scale-down. The next step is to move to the nearest position. If the example is rounded down, it seems wrong, for example, x = 0.5, y = 1.499999, but the difference between x and y is still less than 1, the distance between adjacent statues is 1, so this is also feasible.
Note: floor and rounding are written.
#include
#include
#include
#include
#include
#include
#include
#include #include
using namespace std;int main() { #ifdef Local freopen("a.in", "r", stdin); #endifint n = 0, m = 0, i = 0;while (cin >> n >> m){double ans = 0.0;for (i = 1; i < n; i++){double pos = (double)i/n * (n+m);ans += fabs(pos - floor(pos+0.5)) / (n+m);}cout << setprecision(4) << fixed << ans*10000 << endl;}}
If the requirements are rigorous, we should be at a distance from the front and back locations. Take a small one and paste the code of a senior friend here, so I will be lazy.
From: http://blog.csdn.net/mr_zys/article/details/17270885
#include
#include
#include
const double len = 10000;int n,m;double d0,d1;int main(){ while(~scanf("%d%d",&n,&m)) { if(m % n == 0) printf("0.0\n"); else { d0 = len / (n * 1.0); d1 = len / ((n + m) * 1.0); double ans = 0.0; for(int i = 1; i < n; i++) {double t = i * d0;int d = floor(t/d1);double t1 = fabs(t - d * d1);double t2 = fabs(t - (d + 1.0) * d1);if(t1 > t2) ans += t2;else ans += t1; } printf("%.4lf\n",ans); } } return 0;}