圆上的等距N个点,每个点相距360/N 度,增加M个点后,每个点相距360/(N+m)度,这N个点可顺时针或逆时针移动
每次取移动的最小值即可算出ans
代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<limits.h>
using namespace std;
double min(double x,double y)
{
return x< y? x: y;
}
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
double d1,d2;
d1= 360.0 / n;
d2= 360.0 / (n+m);
double ans= 0.0;
for(int i=1,j=1; i< n && j<= n+m; j++)
{
double t1,t2,t3;
t1= i* d1;
t2= j* d2;
t3= (j+1)* d2;
if(t1>= t2 && t1<= t3)
{
ans+= min(t1- t2, t3- t1);
i++;
}
}
ans= ans/360;
printf("%.4lf\n",ans*10000);
}
return 0;
}