码迷,mamicode.com
首页 > 其他好文 > 详细

uva 1388

时间:2017-08-05 12:36:42      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:using   class   cst   std   for   数学   str   algo   ace   

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

#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

标签:using   class   cst   std   for   数学   str   algo   ace   

原文地址:http://www.cnblogs.com/Wangwanxiang/p/7289787.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!