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. 小米范工具系列之十:小米范SSH批量命令执行工具

    小米范SSH批量命令执行工具的主要功能是自动登录多台机器,并执行指定的命令,比如批量抓取shadow.批量获取系统版本.或者做基线时批量抓取配置等. 此工具使用java 1.8以上版本运行. 界面如下 ...

  2. Django自带的加密算法及加密模块

    Django 内置的User类提供了用户密码的存储.验证.修改等功能,可以很方便你的给用户提供密码服务. 默认的Ddjango使用pbkdf2_sha256方式来存储和管理用的密码,当然是可以自定义的 ...

  3. logging.basicConfig参数简介

    通过logging.basicConfig函数对日志的输出格式及方式做相关配置 import logging logging.basicConfig(level=logging.DEBUG, form ...

  4. 【云安全与同态加密_调研分析(8)】同态加密技术及其应用分析——By Me

    ◆同态加密技术(Homomorphic Encryption, HE)及其应用◆ ◆加密方案◆ ◆应用领域◆ ◆厂商◆ ◆同态加密现有产品形态和工程实现◆ ◆参考链接◆ ◆备注(其他参考信息)◆ 同态 ...

  5. Mirror--使用证书配置镜像模板

    --==================================================================--该文档主要用于内部配置模板--场景:--主服务器:192.1 ...

  6. 不登录到MySQL执行SQL语句

    mysql -e 不登录到MySQL执行SQL语句 mysql -u root -p -e "SHOW DATABASES"

  7. Elasticsearch查询规则(一)match和term

    es种有两种查询模式,一种是像传递URL参数一样去传递查询语句,被称为简单搜索或查询字符串(query string)搜索,比如 GET /megacorp/employee/_search //查询 ...

  8. Python第二弹--------类和对象

    Python中的任何一条数据都是对象.每个对象都由3部分组成:标识.类型和值.对象的标识代表该对象在内存中的存储位置(因此是不可更改的),对象的类型表明它可以拥有数据和值的类型. 创建 Dog 类根据 ...

  9. PAT 1137 Final Grading[一般][排序]

    1137 Final Grading(25 分) For a student taking the online course "Data Structures" on China ...

  10. 史上最全的MonkeyRunner自动化测试从入门到精通(3)

    原文地址https://blog.csdn.net/liu_jing_hui/article/details/60956088 MonkeyRunner复杂的功能开始学习 (1)获取APK文件中ID的 ...