sgu 146. The Runner 取模技巧 难度:1
2014-11-02 15:38
447 查看
146. The Runner
[align=center]time limit per test: 0.25 sec.memory limit per test: 4096 KB[/align]
[align=center]input: standard input
output: standard output[/align]
[align=left]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.[/align]
[align=left]
Input[/align]
[align=left]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).[/align]
[align=left]
Output[/align]
[align=left]Write the only one real number with 4 digits after decimal points: the distance from start to finish.[/align]
[align=left]
Sample test(s)[/align]
[align=left]
Input[/align]
[align=left] [/align]
[align=left] [/align]
[align=left]2 1
1 3[/align]
[align=left] [/align]
[align=left] [/align]
[align=left]
Output[/align]
[align=left] [/align]
[align=left] [/align]
[align=left]1.0000[/align]
感想:使用了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\n",(double)ans/10000.0); return 0; }
相关文章推荐
- SGU 146.The Runner
- sgu 146 The Runner
- sgu 146 The Runner
- SGU146 The Runner
- SGU 146 The Runner(水~)
- sgu108. Self-numbers 2 滚动数组 打表 难度:1
- sgu 142. Keyword 暴力,hash 难度:0
- sgu 147. Black-white king 思路 坑 难度:1
- 快速切题 sgu 111.Very simple problem 大数 开平方 难度:0 非java:1
- SGU 140. Integer Sequences 线性同余,数论 难度:2
- sgu 137. Funny Strings 线性同余,数论,构造 难度:3
- SGU 110. Dungeon 计算几何 难度:3
- SGU 219 Synchrograph tarjian找环,理解题意,图论 难度:3
- sgu 122. The book 满足ore性质的汉密尔顿回路 难度:2
- sgu 129 Inheritance 凸包,线段交点,计算几何 难度:2
- SGU 125. Shtirlits 剪枝技巧
- SGU 156 Strange Graph 欧拉回路,思路,汉密尔顿回路 难度:3
- SGU 131. Hardwood floor 状压dp 难度:2
- sgu101 欧拉路径 难度:1
- 快速切题 sgu105. Div 3 数学归纳 数位+整除 难度:0