D - Subway

Description
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
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
Output is the number of minutes it will take you to get to school, rounded to the nearest minute, taking the fastest route.
Sample Input
0 0 10000 1000
0 200 5000 200 7000 200 -1 -1
2000 600 5000 600 10000 600 -1 -1
Sample Output
21

题意:给出起点和终点,给出每一条地铁线上的地铁站,一条线上的相邻地铁站能坐地铁,其余的只能走路,问从起点到终点的最快时间。

相邻地铁站用地铁站建边,然后再整幅图建走路的边。跑一遍最短路(spfa)。

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
const int MAXM=40005;
const int MAXN=205;
using namespace std;
int tol;
bool vis[MAXN];
double dir[MAXM];
struct q
{
    int u,v,w;
}road[MAXM];
struct Edge
{
    int v;
    double w;
};
vector<Edge> edge[MAXM];
double walktime(int x1,int y1,int x2,int y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/1000.0*6.0;
}
double subtime(int x1,int y1,int x2,int y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/4000.0*6.0;
}
void add(int u,int v,double w)
{
    /*edge[tol].u=u;
    edge[tol].v=v;
    edge[tol++].w=w;*/
    Edge tmp;
    tmp.v=v;
    tmp.w=w;
    edge[u].push_back(tmp);
}
void spfa(int from)
{
    memset(vis,false,sizeof(vis));
    //memset(dir,0x3f,sizeof(dir));
    for(int i=0;i<MAXM;i++)
    {
        dir[i]=10000000001;
    }
    dir[from]=0;
    vis[from]=true;
    queue<int>que;
    while(!que.empty())
    {
        que.pop();
    }
    que.push(from);
    while(!que.empty())
    {
        int now=que.front();
        que.pop();
        vis[now]=false;
        for(int i=0;i<edge[now].size();i++)
        {
            if(dir[edge[now][i].v]>edge[now][i].w+dir[now])
                {
                    dir[edge[now][i].v]=edge[now][i].w+dir[now];
                    if(!vis[edge[now][i].v])
                    {
                        que.push(edge[now][i].v);
                        vis[edge[now][i].v]=true;
                    }
                }
        }
    }
}
int main (void)
{
    int x1,y1,x2,y2;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    double le=walktime(x1,y1,x2,y2);
    road[1].u=x1,road[1].v=y1;
    road[2].u=x2,road[2].v=y2;
    add(1,2,le);
    int cnt=3;
    int i=3;
    //int flag=1;
    int x,y;
    while(~scanf("%d %d",&x,&y))
        {
            if(x==-1&&y==-1)
                {
                    for(;i<cnt-1;i++)
                    {
                        le=subtime(road[i].u,road[i].v,
                            road[i+1].u,road[i+1].v);
                        add(i,i+1,le);
                        add(i+1,i,le);
                    }
                    i++;//注意
                    continue;
                }
            else
            {   
            road[cnt].u=x;
            road[cnt].v=y;
            cnt++;
            }
        }
        for(int i=1;i<cnt;i++)
        {
            for(int j=i+1;j<cnt;j++)
            {
                le=walktime(road[i].u,road[i].v,road[j].u,road[j].v);
                add(i,j,le);
                add(j,i,le);
            }
        }
        spfa(1);
        printf("%.0f\n",dir[2]);
        return 0;
}
### 安装 `scikit-learn` 出现致命错误的原因分析 在 Windows 平台上安装 Python 包时,可能会遇到类似于 `Fatal error in launcher: Unable to create process using` 的错误。这种问题通常与系统的路径配置有关,尤其是当路径中包含空格(如默认的 `C:\Program Files\Python3x` 文件夹)。此错误的根本原因在于命令启动器无法正确解析带有空格的路径[^1]。 为了有效解决问题并成功安装 `scikit-learn`,可以采取以下方法: --- #### 方法一:升级 Pip 工具 Pip 是管理 Python 包的核心工具,旧版本可能存在兼容性问题。通过升级到新版 Pip 可能会修复部分已知问题。推荐使用以下方式安全升级 Pip: ```python python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 上述命令利用清华大学开源镜像源加速下载过程,并确保 Pip 升级至新稳定版本[^2]。 --- #### 方法二:重新设置环境变量 如果路径中的空格确实引发冲突,则可以通过调整 Python 的安装位置来规避这一问题。具体操作如下: 1. **卸载当前 Python 版本**; 2. 在重新安装过程中,选择自定义选项并将目标目录更改为无空格路径(例如 `C:\Python39`); 3. 确认勾选“Add Python to PATH”,以便自动更新系统环境变量。 完成以上步骤后再尝试运行原始命令即可正常工作。 --- #### 方法三:单独安装依赖项 有时即使解决了基础性的技术障碍,在实际执行 `pip install scikit-learn` 过程里仍可能出现额外缺失组件提示。比如之前提到过的 `tqdm` 和 `numpy` 就属于此类情况[^3]。因此建议先手动预加载这些必要库文件再继续后续流程: ```bash pip install numpy scipy joblib threadpoolctl Cython ``` 之后再次发起针对 `scikit-learn` 的请求应该就不会碰到阻碍了。 --- ### 总结 综上所述,处理 `Fatal error in launcher: Unable to create process using` 错误需综合考虑多方面因素,包括但不限于修正潜在不恰当设定以及补充完善关联资源列表等内容。按照前述指导逐一排查直至终达成预期成果为止。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值