Subway

题目描述:

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don’t want to be late for class, you want to know how long it will take you to get to school.
You walk at a speed of 10 km/h. The subway travels at 40 km/h. Assume that you are lucky, and whenever you arrive at a subway station, a train is there that you can board immediately. You may get on and off the subway any number of times, and you may switch between different subway lines if you wish. All subway lines go in both directions.

输入:

Input consists of the x,y coordinates of your home and your school, followed by specifications of several subway lines. Each subway line consists of the non-negative integer x,y coordinates of each stop on the line, in order. You may assume the subway runs in a straight line between adjacent stops, and the coordinates represent an integral number of metres. Each line has at least two stops. The end of each subway line is followed by the dummy coordinate pair -1,-1. In total there are at most 200 subway stops in the city.

输出:

Output is the number of minutes it will take you to get to school, rounded to the nearest minute, taking the fastest route.

样例输入:

0 0 10000 1000
0 200 5000 200 7000 200 -1 -1 
2000 600 5000 600 10000 600 -1 -1

样例输出:

21

题目大意:

一个人从家要到学校去,途中有许多车站,所以有步行和做地铁两种方式,其速度分别是10km/h 和40km/h。输入的规则是第一行输入的是x1,y1,x2,y2,分别代表家的坐标和学校的坐标。以后输入的是车站的坐标,数目不超过200,相邻的两个站点可以坐地铁,其他的需要步行。问到达学校的最短时间是多少?
思路:
其实只是一个最短路径问题,只是建图比较麻烦,当然,很可能是题目没有看懂
还是想吐槽一下机翻

code:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
const int maxn=450;
const double inf=999999.99;
int cnt;
struct node{
	int x,y;
}feng[maxn];
double a[maxn][maxn];
double d[maxn];
int visit[maxn];
double juli(int a,int b,int x,int y)
{
	return sqrt((a-x)*(a-x)+(b-y)*(b-y));
}
void dijkstra(int start)
{
	fill(d,d+cnt,inf);
	memset(visit,0,sizeof(visit));
	d[start]=0.0;
	while(1)
	{
		int v=-1;
		for(int i=0;i<cnt;i++)
		{
			if(visit[i]==0&&(v==-1||d[i]<d[v]))
				v=i;
		}
		if(v==-1)break;
		visit[v]=1;
		for(int i=0;i<cnt;i++)
		{
			d[i]=min(d[i],d[v]+a[v][i]);
		}
	}
	printf("%.0f\n",d[1]*60.0);
}
int main()
{
	scanf("%d%d%d%d",&feng[0].x,&feng[0].y,&feng[1].x,&feng[1].y);
	int x,y;
	cnt=2;
	int tra=2;
	while(scanf("%d%d",&x,&y)!=EOF)
	{
		if(x==-1&&y==-1)
		{
			for(int i=tra;i<cnt-1;i++)
			{
				a[i][i+1]=a[i+1][i]=juli(feng[i].x,feng[i].y,feng[i+1].x,feng[i+1].y)/40000.0; 
			}
			tra=cnt;//下一班的列车
			continue;
		}
		else
		{
			feng[cnt].x=x;
			feng[cnt++].y=y; 
		}
	}
	for(int i=0;i<cnt;i++)
	{
		for(int j=i+1;j<cnt;j++)
		{
			if(a[i][j]==0)
			{
				a[i][j]=a[j][i]=juli(feng[i].x,feng[i].y,feng[j].x,feng[j].y)/10000.0;
			}
		}
	}
	dijkstra(0);
	return 0;
}

### 如何获取 Subway 数据集 Subway 数据集是一个用于异常事件检测研究的公开数据集,其中包含了地铁站入口 (Subway entrance) 和地铁站出口 (Subway exit) 的视频片段。这些视频主要用于分析诸如错误方向、逃票和徘徊等异常行为 [^1]。 然而,在已知的信息中并未提供该数据集的具体下载地址 。通常情况下,如果官方文档或论文未明确给出下载链接,则可能需要通过以下方法尝试获取: #### 方法一:联系作者 部分学术数据集由研究人员发布并维护,因此可以通过查阅原始论文找到作者联系方式,并向其发送邮件请求访问权限或具体下载方式。 #### 方法二:查找替代资源 虽然当前引用中的 `Subway` 数据集没有直接可用的下载链接,但可以考虑其他类似的公共数据集作为补充材料。例如: - **Avenue 数据集**: 提供了监控场景下的正常与异常活动录像,适用于异常检测算法的研究 [^2]。 - **ShanghaiTech 数据集**: 这也是一个关于人群计数及异常识别的任务集合 。 对于特定提到的 `subway` 数据库以及关联文件 (`city_subway_system`) ,有第三方博客建议从个人分享页面或者相关课程资料里寻找相关内容 [^3] 。不过需要注意的是这类非正式渠道可能存在版本差异甚至版权风险等问题 。 以下是基于 Python 实现的一个简单脚本示例来演示如何自动化处理此类问题(假设我们已经获得了合法授权后的压缩包路径): ```python import os from zipfile import ZipFile def extract_dataset(zip_path, target_dir): """Extract a given zip file to the specified directory.""" with ZipFile(zip_path, 'r') as zipped_file: zipped_file.extractall(target_dir) if __name__ == "__main__": dataset_zip = "/path/to/downloaded/Subway_Dataset.zip" extraction_folder = "./datasets/subway/" if not os.path.exists(extraction_folder): os.makedirs(extraction_folder) try: extract_dataset(dataset_zip, extraction_folder) print(f"Dataset extracted successfully into {extraction_folder}.") except Exception as e: print("An error occurred while extracting:", str(e)) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值