POJ 1192 限制条件最短路
来源:互联网 发布:easing.js 编辑:程序博客网 时间:2024/05/21 13:57
通道在一定的时间开放,处理一下就是最短路了
strtok(char[], " ")还是很好用的
引用一下百度百科
strtok()用来将字符串分割成一个个片段。参数s指向欲分割的字符串,参数delim则为分割字符串中包含的所有字符。当strtok()在参数s的字符串中发现参数delim中包涵的分割字符时,则会将该字符改为\0 字符。在第一次调用时,strtok()必需给予参数s字符串,往后的调用则将参数s设置成NULL。每次调用成功则返回指向被分割出片段的指针。
for (i = 0, p = strtok(str, " "); p != NULL; ++i) { a[i] = atoi(p); p = strtok(NULL, " "); }
atof(将字符串转换成浮点型数)
atoi(将字符串转换成整型数)
atol(将字符串转换成长整型数)
strtod(将字符串转换成浮点数)
strtol(将字符串转换成长整型数)
strtoul(将字符串转换成无符号长整型数)
SFPA
#include <set>#include <map>#include <cmath>#include <queue>#include <stack>#include <string>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const double PI = acos(-1.0);template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;}template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;}const int N = 111;const int M = 11111;const LL MOD = 1000000007LL;const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};const int INF = 0x3f3f3f3f;struct node{ int w, next, v, ways; int ti[20][2];}edge[1111];int cnt, head[55];int n, m, s, t;char str[1111];int dist[55];bool inq[55];void add(){ int a[45]; char *p; int i, j, k, u, v; for (i = 0, p = strtok(str, " "); p != NULL; ++i) { a[i] = atoi(p); p = strtok(NULL, " "); } edge[cnt].w = a[2]; edge[cnt].v = a[1]; edge[cnt].next = head[a[0]]; a[2] = 0; for (j = 3, k = 0; j < i; j +=2, ++k) { edge[cnt].ti[k][0] = a[j - 1]; edge[cnt].ti[k][1] = a[j]; } if (i == j) { edge[cnt].ti[k][0] = a[j - 1]; edge[cnt].ti[k][1] = INF; k++; } edge[cnt].ways = k; head[a[0]] = cnt++; edge[cnt] = edge[cnt - 1]; edge[cnt].v = a[0]; edge[cnt].next = head[a[1]]; head[a[1]] = cnt++;}void solve(){ fill(dist, dist + n + 1, INF); memset(inq, false, sizeof(inq)); dist[s] = 0; queue < int > q; q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); inq[u] = false; int i, j, k; for (i = head[u]; i != -1; i = edge[i].next) { for (k = 0; k < edge[i].ways; ++k) { if (edge[i].ti[k][1] >= MAX(edge[i].ti[k][0], dist[u]) + edge[i].w) { if (MAX(edge[i].ti[k][0], dist[u]) + edge[i].w < dist[edge[i].v]) { dist[edge[i].v] = MAX(edge[i].ti[k][0], dist[u]) + edge[i].w; if (!inq[edge[i].v]) {inq[edge[i].v] = true; q.push(edge[i].v);} } } } } } if (dist[t] == INF) printf("*\n"); else printf("%d\n", dist[t]);}int main(){ while (scanf("%d", &n) != EOF && n) { scanf("%d%d%d", &m, &s, &t); int i, u, v; cnt = 0; memset(head, -1, sizeof(head)); getchar(); for (i = 0; i < m; ++i) { gets(str); add(); } if (s == t) printf("0"); else solve(); } return 0;}
- POJ 1192 限制条件最短路
- poj 1724 有限制条件的最短路
- POJ 1724 最短路费用限制
- poj 1062(有限制的最短路)
- poj 1724(有限制的最短路)
- 【poj】【费用限制最短路】ROADs
- 【POJ 1724】Roads (限制最短路)
- POJ1724 ROADS(加限制条件的最短路,深搜)
- Roads带限制条件的最短路算法
- POJ 1062 昂贵的聘礼 最短路枚举等级限制
- poj 1724 ROADS 加限制的最短路
- POJ 1724 优先队列解带限制最短路
- POJ 1724 - ROADS 有限制的最短路,A*
- poj 1062 昂贵的聘礼 (有限制的最短路)
- POJ 3594 带限制的最短路 枚举+SPFA
- POJ 1062 昂贵的聘礼(限制的最短路)
- Poj 1724 ROADS【二维限制最短路+SPFA】
- POJ 1724 ROADS (有限制的最短路)
- 国家气象局免费天气预报接口API
- rqn 137 找试场(模拟)
- Shell编程学习---第五篇:Shell的输入和输出
- IOS登陆+注册+抽奖+排行榜
- 网络流 dicnic sap 2种算法详细解释 以及例题POJ1459
- POJ 1192 限制条件最短路
- ubuntu中关闭防火墙
- 【C++沉思录】构造函数与析构函数的出现时机
- Web版RSS阅读器(四)——定制自己的Rss解析库myrsslib4j
- C++隐藏任务栏和桌面
- C++中public,protected,private访问
- 【C++沉思录】数组和指针的寻址
- 【C++沉思录】switch比if else要高效的原因
- localhost 和 127.0.0.1的区别