sgu 146 The Runner

18 篇文章 0 订阅
146. The Runner
time limit per test: 0.5 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



大水题啊,就是实数转成整数就可以了,但是L转化的时候要加上 0.001 啊之类的较小的树,否则就WA#8 或WA# 14 了。好诡异啊,感谢discuss里大牛的留言啊。

贴贴代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>
#include<cstdlib>

#define inf 0xfffffff
#define CLR(a,b) memset((a),(b),sizeof((a)))
#define FOR(a,b) for(int a=1;a<=(b);(a)++)

using namespace std;
int const nMax = 1010;
int const base = 10;
typedef long long LL;
typedef pair<LL,LL> pij;

//    std::ios::sync_with_stdio(false);

set<LL> Q;
int n;
float l;
LL L;
LL u,t,s,v;


int main(){
    s=0;
    scanf("%f%d",&l,&n);
    L=(l+0.000001)*10000;
    FOR(i,n) {
        scanf("%I64d%I64d",&t,&u);
        u=(u*10000)%L;
        t=t%L;
        s+=u*t;
        s%=L;
    }
    LL ans=min(s,L-s);
    printf("%.4lf\n",(double)ans/10000.0);
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值