HDU 5163 Taking Bus
来源:互联网 发布:石家庄 软件开发培训 编辑:程序博客网 时间:2024/05/21 06:22
Taking Bus
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 193 Accepted Submission(s): 89
Problem Description
Bestland has a very long road and there aren bus station along the road, which are numbered 1 to n from left to right. There are m persons wanting to take the bus to some other station. You task is to find the time needed for each person. Note: All the other information you need is below. Please read the statment carefully.
Input
There are multiple test cases. The first line of input contains an integerT (1≤T≤60) , indicating the number of test cases. For each test case: The first line contains two integersn and m (2≤n,m≤105) , indicating the number of bus stations and number of people. In the next line, there aren−1 integers, d1,d2,…,dn−1 (1≤di≤109 ). The i -th integer means the distance between bus station i and i+1 is di (1≤i<n ). In the next m lines, each contains two integers xi and yi (1≤xi,yi≤n,xi≠yi ), which means i -th person is in bus station xi and wants goto bus station yi .(1≤i≤m)
What else you should know is that for thei -th person, the bus starts at bus station ((i−1) mod n)+1 and drives to right. When the bus arrives at station n , it will turn around and drive from right to left. Similarly, When the bus arrives at station1 , it will turn around and drive from left to right. You can assume that the bus drives one meter per second. And you should only consider the time that the bus drives and ignore the others.
What else you should know is that for the
Output
For each person, you should output one integer which is the minimum time needed before arriving bus stationyi .
Sample Input
17 32 3 4 3 4 51 74 55 4
Sample Output
211028HintFor the first person, the bus starts at bus station 1, and the person takes in bus at time 0. After 21 seconds, the bus arrives at bus station 7. So the time needed is 21 seconds. For the second person, the bus starts at bus station 2. After 7 seconds, the bus arrives at bus station 4 and the person takes in the bus. After 3 seconds, the bus arrives at bus station 5. So the time needed is 10 seconds. For the third person, the bus starts at bus station 3. After 7 seconds, the bus arrives at bus station 5 and the person takes in the bus. After 9 seconds, the bus arrives at bus station 7 and the bus turns around. After 12 seconds, the bus arrives at bus station 4. So the time needed is 28 seconds.
Source
BestCoder Round #27
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5163
题目大意:n个车站,两两相邻距离为d[i],车子开到底站就掉头,对于第i个人车子的起始位置为((i−1) mod n)+1 ,m个人,求每个人从A站到B站的时间
题目分析:预处理+分类讨论小模拟,先求出从第一个点到其余各点的距离,然后分四类
起点 <= A <= B
起点 <= A,A >= B
起点 >= A,A <= B
起点 >= A,A >= B
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5163
题目大意:n个车站,两两相邻距离为d[i],车子开到底站就掉头,对于第i个人车子的起始位置为
题目分析:预处理+分类讨论小模拟,先求出从第一个点到其余各点的距离,然后分四类
起点 <= A <= B
起点 <= A,A >= B
起点 >= A,A <= B
起点 >= A,A >= B
#include <cstdio>#define ll long longll dis[100005];int main(){ int T, n, m; scanf("%d", &T); while(T--) { int x, y; ll ans, tmp; scanf("%d %d", &n, &m); dis[1] = 0; for(int i = 2; i <= n; i++) { scanf("%lld", &tmp); dis[i] = dis[i - 1] + tmp; } for(int i = 0; i < m; i++) { ans = 0; scanf("%d %d", &x, &y); int st = (i % n) + 1; if(st <= x && x <= y) ans = dis[y] - dis[st]; else if(st <= x && x >= y) { ans += (dis[n] - dis[st]); ans += (dis[n] - dis[y]); } else if(st >= x && x <= y) { ans += (dis[n] - dis[st]); ans += (dis[n] - dis[x]); ans += (dis[x] - dis[1]); ans += (dis[y] - dis[1]); } else if(st >= x && x >= y) { ans += (dis[n] - dis[st]); ans += (dis[n] - dis[y]); } printf("%lld\n", ans); } }}
0 0
- HDU 5163 Taking Bus
- HDU 5163 Taking Bus
- HDU 5163 Taking Bus
- hdu 5163 Taking Bus 水题
- hdu 5163 Taking Bus (BestCoder Round #27)
- hdu 5163 Taking Bus(模拟)
- 杭电 hdu 5163 Taking Bus【模拟】
- hdu 5163 Taking Bus(模拟)
- 【BestCoder】 HDOJ 5163 Taking Bus
- 【CUGBACM15级BC第27场 B】hdu 5163 Taking Bus
- hdu5163---Taking Bus
- bestcoder 1002 Taking Bus
- Bestcoder_Round#27_1002-Taking bus(HDUOJ_5163)
- HDU 3262 Seat taking up is tough
- HDU 3262 Seat taking up is tough
- HDU 1690 Bus System
- HDU 1690 Bus System
- hdu 1690 Bus System
- Win7登陆管理员账户
- Redis研究(十四)—管理工具
- GPUImage.h简单说明
- HDU2103 Family planning【水题】
- 浅谈mysql配置优化和sql语句优化
- HDU 5163 Taking Bus
- Android 无线调试
- hdu 5154 拓扑排序
- weblogic启动报Server may already be running
- 高等数学(总结5)
- 接口隔离原则
- HBase source code. KeyValue
- Python读书笔记-第五章
- 图像直方图均衡化