HDU5163Taking Bus

Taking Bus

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1209    Accepted Submission(s): 383


Problem Description
Bestland has a very long road and there are n 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 integer T (1T60), indicating the number of test cases. For each test case: The first line contains two integers n and m (2n,m105), indicating the number of bus stations and number of people. In the next line, there are n1 integers, d1,d2,,dn1 (1di109). The i-th integer means the distance between bus station i and i+1 is di (1i<n). In the next m lines, each contains two integers xi and yi (1xi,yin,xiyi), which means i-th person is in bus station xi and wants goto bus station yi(1im)

What else you should know is that for the i-th person, the bus starts at bus station ((i1) 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 station 1, 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.
 

Output
For each person, you should output one integer which is the minimum time needed before arriving bus station yi.
 

Sample Input
1 7 3 2 3 4 3 4 5 1 7 4 5 5 4
 

BEST CODE 里面的题目,看不懂题意的可以去看中文版的:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=563&pid=1002

不是很难,也是水题;理解题意就可以知道,只要分三种情况,就可以做了;

给出代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int sta[100005];//存取每个公交站点之间的距离
long long suml[100005];//计算每个公交站点到第一个公交站点的距离
long long sum[100005];//存取每一组数据所花费的最少时间;
int main()
{
	int T,n,m,start,end;
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d%d",&n,&m);
		long long num=0;
		for (int i = 2; i <= n; i++)
		{
			scanf("%lld", &sta[i]);
			num += sta[i];
			suml[i] = num;             //处理每一个公交站点到第一个公交站点的距离;
		}
		for (int count = 1; count <= m; count++)  //计数,
		{
			scanf("%d%d",&start,&end);
			int Staion = (count - 1) % n + 1;//第count个人要坐车时,公交车的起始站点位置;
//最好画图模拟下,这是人的终点站点标号>起始站点标号,并且公交车的起始站点标号<=人的起始站点标号的情况;
			if (end>start&&Staion<=start)   
			{
				
				sum[count] = suml[end] - suml[Staion];
			}
//人的终点站点标号>起始站点标号,并且公交车的起始站点标号 > 人的起始站点标号的情况;
			else if (end>start&&Staion > start)
			{
				sum[count] = 2 * suml[n] - suml[Staion] + suml[end];
			}
//人的终点站点标号<起始站点标号,并且公交车的起始站点标号 > 人的起始站点标号或者公交车的起始站点标号<=人的起始站点标号的情况;;
			else if (start > end)
			{
				sum[count] = 2 * suml[n] - suml[Staion] - suml[end];
			}
		}
		for (int i = 1; i <= m; i++)
			printf("%lld\n", sum[i]);
	}
	return 0;
}


下载前可以先看下教程 https://pan.quark.cn/s/16a53f4bd595 小天才电话手表刷机教程 — 基础篇 我们将为您简单的介绍小天才电话手表新机型的简单刷机以及玩法,如adb工具的使用,magisk的刷入等等。 我们会确保您看完此教程后能够对Android系统有一个最基本的认识,以及能够成功通过magisk root您的手表,并安装您需要的第三方软件。 ADB Android Debug Bridge,简称,在android developer的adb文档中是这么描述它的: 是一种多功能命令行工具,可让您与设备进行通信。 该命令有助于各种设备操作,例如安装和调试应用程序。 提供对 Unix shell 的访问,您可以使用它在设备上运行各种命令。 它是一个客户端-服务器程序。 这听起来有些难以理解,因为您也没有必要去理解它,如果您对本文中的任何关键名词产生疑惑或兴趣,您都可以在搜索引擎中去搜索它,当然,我们会对其进行简单的解释:是一款在命令行中运行的,用于对Android设备进行调试的工具,并拥有比一般用户以及程序更高的权限,所以,我们可以使用它对Android设备进行最基本的调试操作。 而在小天才电话手表上启用它,您只需要这么做: - 打开拨号盘; - 输入; - 点按打开adb调试选项。 其次是电脑上的Android SDK Platform-Tools的安装,此工具是 Android SDK 的组件。 它包括与 Android 平台交互的工具,主要由和构成,如果您接触过Android开发,必然会使用到它,因为它包含在Android Studio等IDE中,当然,您可以独立下载,在下方选择对应的版本即可: - Download SDK Platform...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值