zoukankan      html  css  js  c++  java
  • sgu 146. The Runner 取模技巧 难度:1

    146. The Runner

    time limit per test: 0.25 sec.
    memory limit per test: 4096 KB
    input: standard input
    output: standard output




    The runner moves along the ring road with length L. His way consists of N intervals. First he ran T1 minutes with speed V1, then T2 minutes with speed V2 and so on till the N-th interval, where he ran TN minutes with speed VN. Your task is to find the distance from start to finish along the ring road. The distance along the ring road is the length of the shortest way all points of which belongs to the ring road.

    Input
    Real number L (1<=L<=1000, with 4 signs after decimal point) and natural number N (N<=20000) are written in the first line. Each of the following N lines contains two integer numbers Ti and Vi (1<=Ti<=10^7, 1<=Vi<=10^6).

    Output
    Write the only one real number with 4 digits after decimal points: the distance from start to finish.

    Sample test(s)

    Input
     
     
    2 1 
    1 3
     
     

    Output
     
     
    1.0000

    感想:使用了double/double的取模..结果过不了,可能还是尾数长度不够的原因,所以还是longlong整除法,似乎longlong*1en再整除更精确

     思路:因为题目是四位数精度,所以sigma(vi*ti)乘上1e4后取余就可以得到当前位置,注意所说的是起点与终点的距离,取劣弧

    #include <cstdio>
    #include <cstring>
    using namespace std;
    const double eps=1e-8;
    
    int n;
    long long t[25001],v[25001];
    int main(){
        double tl;
        long long l;
        scanf("%lf%d",&tl,&n);
        l=tl*10000+0.5;
        for(int i=0;i<n;i++){
            scanf("%I64d%I64d",t+i,v+i);
        }
        long long ans=0;
        for(int i=0;i<n;i++){
            ans+=t[i]*v[i]*10000;
            ans%=l;
        }
        if(l-ans<ans)ans=l-ans;
        printf("%.4f
    ",(double)ans/10000.0);
        return 0;
    }
    

      

  • 相关阅读:
    html5 canvas 渐变
    html5 canvas 画直线
    html5在canvas中插入图片
    Window文件夹右击菜单定制
    HTML中解决双击会选中文本的问题
    Linux 下修改mysql 字符集编码
    mysqlimport导入命令使用
    PAM 2500 荧光数据导出数据整合脚本
    Resources for Ecology and Evolution
    Plant Ecology Journal Club, 分享主题和文献列表 825, 2019年春
  • 原文地址:https://www.cnblogs.com/xuesu/p/4069358.html
Copyright © 2011-2022 走看看