uva 1388

Posted 发牌员

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva 1388相关的知识,希望对你有一定的参考价值。

数学加脑洞吧,主要是脑洞

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
double n,m;
int main()
{
    while(~scanf("%lf%lf",&n,&m))
    {
        double ans=0;
        for(double i=1.0;i<n;i+=1.0)
        {
             double pos=i/n*(n+m);//把数轴总长度由n扩大到n+m,pos也就是原坐标在新数轴里的坐标
             ans+=fabs(pos-floor(pos+0.5))/(n+m);//最终点肯定是整点坐标,记住缩回到数轴长度为1
        }
        printf("%.4lf\n",ans*10000.0);//扩大10000倍
    }
    return 0;
}

 

以上是关于uva 1388的主要内容,如果未能解决你的问题,请参考以下文章