uva 1388

这个题的方法很巧妙,首先将整个圆分成(m+n)份,这样移动后的点都是在整数值上;

所以只要计算在这样的分法下原来的坐标就行了;

代码:

 1 #include<cstdio>
 2 #include<cmath>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int m,n;
 8     {
 9         while(scanf("%d%d",&n,&m)!=EOF)
10         {
11             double ans=0;
12             for(int i=1;i<n;i++)
13             {
14                 double pos=(double)i/n*(n+m);
15                 ans+=fabs(pos-floor(pos+0.5))/(n+m);
16             }
17             printf("%.4lf
",ans*10000);
18         }
19     }
20     return 0;
21 }
View Code
原文地址:https://www.cnblogs.com/yours1103/p/3388716.html