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\n",(double)ans/10000.0);
return 0;
}

  

sgu 146. The Runner 取模技巧 难度:1的更多相关文章

  1. SGU 146.The Runner

    时间限制:0.25s 空间限制:4M 题意: 一个人在一个周长为L的圆上跑,每个时间段(Ti)的速度(Vi)不一样,问最后他离起点的圆弧距离,周长是个有四位小数的浮点数,其它全是整数. Solutio ...

  2. 【BZOJ】3751: [NOIP2014]解方程【秦九韶公式】【大整数取模技巧】

    3751: [NOIP2014]解方程 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 4856  Solved: 983[Submit][Status ...

  3. ACM-较大的数乘法取模技巧*

    比如模数是1e15这种,相乘的时候爆LL了,但是又不想用大数,咋办呢? long long ksc(long long a, long long b, long long mod){ ; while( ...

  4. HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)

    传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...

  5. hdu 5265 技巧题 O(nlogn)求n个数中两数相加取模的最大值

    pog loves szh II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. NYOJ--102--次方求模(快速求幂取模)

    次方求模 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 求a的b次方对c取余的值   输入 第一行输入一个整数n表示测试数据的组数(n<100)每组测试只有一 ...

  7. 位运算之——按位与(&)操作——(快速取模算法)

    学习redis 字典结构,hash找槽位 求槽位的索引值时,用到了 hash值 & sizemask操作, 其后的scan操作涉及扫描顺序逻辑,对同模的槽位 按一定规则扫描! 其中涉及位运算 ...

  8. 【Java基础】14、位运算之——按位与(&)操作——(快速取模算法)

    学习redis 字典结构,hash找槽位 求槽位的索引值时,用到了 hash值 & sizemask操作, 其后的scan操作涉及扫描顺序逻辑,对同模的槽位 按一定规则扫描! 其中涉及位运算 ...

  9. [hdu5392 Infoplane in Tina Town]置换的最小循环长度,最小公倍数取模,输入挂

    题意:给一个置换,求最小循环长度对p取模的结果 思路:一个置换可以写成若干循环的乘积,最小循环长度为每个循环长度的最小公倍数.求最小公倍数对p取模的结果可以对每个数因式分解,将最小公倍数表示成质数幂的 ...

随机推荐

  1. UML Diagrams Using Graphviz Dot

    Introduction Background This article is about using the dot tool from the Graphviz package to automa ...

  2. JAVA中传递的值还是引用的问题

    public static void main(String[] args) { /*byte b[] = new byte[1024*1024*50]; System.out.println(b); ...

  3. 提高myEclipse的开发效率和外观,这些你都设置了吗?

    [前言] 为什么我的myeclipse开启速度那么慢,为什么别人能哗啦啦几个快捷键打出一片代码?刚开始使用myeclipse的时候,相信大家都有这个疑问,慢慢的,也懂得一些配置,我也不例外,在此,把常 ...

  4. arc 和 非arc兼容

    1,选择项目中的Targets,选中你所要操作的Target, 2,选Build Phases,在其中Complie Sources中选择需要ARC的文件双击, 并在输入框中输入:-fobjc-arc ...

  5. Flask系列(一)flask入门

    一.Flask介绍(轻量级的框架,非常快速的就能把程序搭建起来) Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是 ...

  6. idea一个类中,各个修饰符的符号表示

    1: 2:

  7. springboot的相关信息

    Maven的配置:zzp_settings.xml <?xml version="1.0" encoding="UTF-8"?> <setti ...

  8. (14)如何使用Cocos2d-x 3.0制作基于tilemap的游戏:第二部分

    引言 程序截图: 这篇教程是<如何使用Cocos2d-x 3.0制作基于tilemap的游戏>的第二部分.在上一个教程中,我们创建了一个简单的基于tiled地图的游戏,里面有一个忍者在沙漠 ...

  9. SQL 处理排序空值

    ①oracle默认排序空值在后面 如果想要排序空值在前面可用关键字 NULLS FIRST, 排序空值在后面也有关键字NULLS LAST ②sqlserver默认排序空值在前面 如果想要排序时空值在 ...

  10. 【运维技术】CentOS7上从零开始安装LAMP安装织梦DedeCMS教程

    前期准备数据 centos7 系统 安装 appache httpd # 更新httpd yum update httpd # 安装httpd yum install -y httpd # 启动服务 ...