这题的算法好神!Orzz

一个周长为10000的圆圈,一开始等距的安放着N个雕塑,现在想增加M个雕塑,使得雕塑之间还是等距,问坟墓最少移动的距离?

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define F 10000
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/n*(n+m);//计算每个需要移动的雕塑的坐标
            ans+=fabs(pos-floor(pos+0.5))/(n+m);//累加移动距离
        }
        printf("%.4lf\n",ans*F);//等比例扩大坐标
    }
    return 0;
}

 

 

相关文章:

  • 2021-08-30
  • 2022-12-23
  • 2021-09-10
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
猜你喜欢
  • 2022-01-26
  • 2021-05-07
  • 2021-10-12
  • 2021-06-15
  • 2021-06-22
  • 2022-12-23
相关资源
相似解决方案