146. The Runner
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
memory limit per test: 4096 KB
input: standard input
output: standard output
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
1 3
Output
1.0000
大水题啊,就是实数转成整数就可以了,但是L转化的时候要加上 0.001 啊之类的较小的树,否则就WA#8 或WA# 14 了。好诡异啊,感谢discuss里大牛的留言啊。
贴贴代码:
大水题啊,就是实数转成整数就可以了,但是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;
}