前言
考虑建图 用 s s t r e a m sstream sstream 处理读入一行很巧妙 传送门 :
思路我们可以 给 一条路线上的所有点都连一条边
这样子处理的话,我们就可以不用考虑 中途是否换车的问题
我们只需要都连一条边 并且 付边权为 1 1 1 即可
最后跑一遍最短路就行
CODE#include
#include
#include
#include
using namespace std;
const int N = 550;
int g[N][N];
int stop[N];
int dist[N];
bool st[N];
int n,m;
int dij()
{
memset(dist,0x3f,sizeof dist);
dist[1] = 0 ;
for(int i = 0;im>>n;
memset(g,0x3f,sizeof g);
string line;
getline(cin,line);///处理最后的回车
while(m -- )
{
string line;
getline(cin,line);
stringstream ssin(line);///过滤数据中的空格
int cnt = 0 , p ;
while(ssin>>p)
stop[cnt++] = p;
///将所有的停车点 相互结合来建图
for(int i=0;i
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?