POJ 1201 差分约束
来源:互联网 发布:js缺少对象,怎样调试 编辑:程序博客网 时间:2024/05/16 17:29
//// main.cpp// POJ 1201 差分约束//// Created by 郑喆君 on 8/8/14.// Copyright (c) 2014 itcast. All rights reserved.////取最大值的时候差分方程形式为a-b<=c 求图的最短距离。取最小值的时候查分方程的形式为a-b>=c,求图的最长距离#include<cstdio>#include<cstring>#include<iostream>#include<iomanip>#include<queue>#include<cmath>#include<stack>#include<map>#include<vector>#include<set>#include<algorithm>using namespace std;typedef long long LL;const int int_max = 0x07777777;const int int_min = 0x80000000;const int maxn = 50005;//struct Edge {// int from, to, dist;// Edge(int _from, int _to, int _dist):from(_from),to(_to),dist(_dist){}//};struct Edge { int to, dist,next;}es[maxn*3];int head[maxn],d[maxn],vis[maxn],cnt;void addedge (int from, int to, int dist){ es[cnt].to = to; es[cnt].dist = dist; es[cnt].next = head[from]; head[from] = cnt++;}int n,s,t;void spfa (){ for(int i = s; i <= t; i++) d[i] = int_min; memset(vis, 0, sizeof(vis)); d[s] = 0; queue<int> q; q.push(s); vis[s] = 1; while(!q.empty()){ int u = q.front(); q.pop(); vis[u] = 0; for(int i = head[u]; i != -1; i = es[i].next){ if(d[es[i].to] < d[u]+es[i].dist){ d[es[i].to] = d[u]+es[i].dist; if(!vis[es[i].to]){ q.push(es[i].to); vis[es[i].to] = 1; } } } }}int main(int argc, const char * argv[]){ while(scanf("%d", &n)!=EOF){ cnt = 0; s = int_max; t = int_min; memset(head, -1, sizeof(head)); for(int i = 0; i < n; i++){ int x,y,z; scanf("%d %d %d", &x, &y, &z); s = (s > x ? x : s); t = (t < y+1 ? y+1 : t); addedge(x, y+1, z); } for(int i = s; i < t; i++) { addedge(i, i+1, 0); addedge(i+1, i, -1); } spfa(); printf("%d\n", d[t]); }}
0 0
- poj 1201 差分约束
- poj 1201 差分约束
- POJ 1201 差分约束
- POJ 1201 差分约束
- POJ 1201 差分约束
- poj 1201 差分约束
- Poj 1201 (差分约束系统)
- POJ 1201 Intervals 差分约束+spfa
- poj 1201 Intervals(差分约束)
- poj 1201 Intervals 差分约束 + spfa
- POJ 1201 Intervals [差分约束]
- POJ 1201 SPFA 差分约束
- poj 1201-差分约束+spfa
- hdu 1384 poj 1201 差分约束
- POJ 1201 (差分约束)
- [差分约束]poj 1201 Interval
- POJ 1201 Intervals(差分约束)
- POJ 1201 Intervals 差分约束系统
- Ali and Snoopy(利用广度搜索走迷宫)
- FadingActionBar的使用
- iReport常见和注意的问题
- (搜索)跳棋系列6
- Intent和PendingIntent的区别
- POJ 1201 差分约束
- Halcon—Tuple中符号的含义
- JDOM解析XML
- pip和easy_install使用方式及pygal安装方式
- cocos2dx 3.1.1 环境搭建 win环境
- Find Metal Mineral
- LeetCode OJ算法题(五十六):Insert Interval
- Fengshui(双向bfs看风水···)
- Android ActionBar动作栏