博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1716 Integer Intervals 差分约束
阅读量:4678 次
发布时间:2019-06-09

本文共 1518 字,大约阅读时间需要 5 分钟。

题目:

1 #include 
2 #include
3 #include
4 #include
5 6 const int INF = 0x3f3f3f3f; 7 8 struct Edge 9 {10 int v, w;11 Edge(){};12 Edge(int v, int w)13 {14 this->v = v;15 this->w = w;16 }17 };18 19 std::vector
map[10010];20 int dist[10010];21 bool inque[10010];22 23 void spfa(int s)24 {25 std::queue
q;26 memset(inque, 0, sizeof(inque));27 dist[s] = 0;28 q.push(s);29 inque[s] = 1;30 while(!q.empty())31 {32 int u = q.front();33 q.pop();34 inque[u] = 0;35 for(int i = 0; i < map[u].size(); i++)36 {37 int v = map[u][i].v;38 if(dist[v] < dist[u] + map[u][i].w)39 {40 dist[v] = dist[u] + map[u][i].w;41 if(!inque[v])42 {43 q.push(v);44 inque[v] = 1;45 }46 }47 }48 }49 }50 51 int main()52 {53 int n;54 int x, y;55 while(scanf("%d", &n) != EOF)56 {57 for(int i = 0; i <= 10001; i++)58 {59 map[i].clear();60 }61 int low = INF, high = 0;62 for(int i = 0; i < n; i++)63 {64 scanf("%d %d", &x, &y);65 map[x].push_back(Edge(y+1, 2));66 if(low > x)low = x;67 if(high < y)high = y;68 }69 for(int i = low; i <= high+1; i++)70 {71 map[0].push_back(Edge(i, 0));72 map[i].push_back(Edge(i+1, 0));73 map[i+1].push_back(Edge(i, -1));74 dist[i] = -INF;75 }76 map[0].push_back(Edge(high+1, 0));77 spfa(low);78 printf("%d\n", dist[high+1] - dist[low]);79 }80 return 0;81 }
View Code

 

转载于:https://www.cnblogs.com/wolfred7464/p/3379416.html

你可能感兴趣的文章
学前班
查看>>
手把手教您扩展虚拟内存
查看>>
android-samples-mvp
查看>>
oracle 11g r2安装
查看>>
关于自关联1
查看>>
存储控制器、MMU、flash控制器介绍
查看>>
hdu-1814(2-sat)
查看>>
自我反省
查看>>
反射,得到Type引用的三种方式
查看>>
pl sql练习(2)
查看>>
Problem B: 判断回文字符串
查看>>
谷歌浏览器,添加默认搜索引擎的搜索地址
查看>>
数据结构化与保存
查看>>
C# .net 获取程序运行的路径的几种方法
查看>>
为什么需要Docker?
查看>>
国内5家云服务厂商 HTTPS 安全性测试横向对比
查看>>
how to control project
查看>>
转 python新手容易犯的6个错误
查看>>
第四节 -- 列表
查看>>
决策树
查看>>