hdu 1384 Intervals 差分约束系统
2015-08-01 14:29
411 查看
注意初始化
#include "stdio.h" #include "string.h" #include "algorithm" #include "queue" #include "vector" using namespace std; const int inf=0x7FFFFFFF; struct node { int to; int c; }; int d[50005],inq[50005]; vector<node>t[50005]; queue<int>q; int main() { int i,n,u,v,w,k,mx,mn; node m; while(~scanf("%d",&n)) { for(i=0;i<50005;i++) { t[i].clear(); d[i]=-inf; inq[i]=0; } while(!q.empty()) q.pop(); mx=0;mn=99999; for(i=0;i<n;i++) { scanf("%d%d%d",&u,&v,&w); m.to=v+1; m.c=w; t[u].push_back(m); if(mx<v) mx=v; if(mn>u) mn=u; } for(i=mn;i<=mx;i++) { m.to=i; m.c=-1; t[i+1].push_back(m); m.to=i+1; m.c=0; t[i].push_back(m); } d[mn]=0; inq[mn]=1; q.push(mn); while(!q.empty()) { u=q.front(); q.pop(); inq[u]=0; for(i=0;i<t[u].size();i++) { v=t[u][i].to; k=t[u][i].c+d[u]; if(d[v]<k) { d[v]=k; if(inq[v]==0) { inq[v]=1; q.push(v); } } } } printf("%d\n",d[mx+1]); } return 0; }
#include "stdio.h" #include "string.h" #include "algorithm" #include "queue" #include "vector" using namespace std; const int inf=0x7FFFFFFF; struct node { int to; int c; }; int d[50005],inq[50005]; vector<node>t[50005]; queue<int>q; int main() { int i,n,u,v,w,k,mx,mn; node m; while(~scanf("%d",&n)) { for(i=0;i<50005;i++) { t[i].clear(); d[i]=inf; inq[i]=0; } while(!q.empty()) q.pop(); mx=0;mn=99999; for(i=0;i<n;i++) { scanf("%d%d%d",&u,&v,&w); m.to=u; m.c=-w; t[v+1].push_back(m); if(mx<v) mx=v; if(mn>u) mn=u; } for(i=mn;i<=mx;i++) { m.to=i+1; m.c=1; t[i].push_back(m); m.to=i; m.c=0; t[i+1].push_back(m); } inq[mx+1]=1; d[mx+1]=0; q.push(mx+1); while(!q.empty()) { u=q.front(); q.pop(); inq[u]=0; for(i=0;i<t[u].size();i++) { v=t[u][i].to; k=t[u][i].c+d[u]; if(d[v]>k) { d[v]=k; if(inq[v]==0) { inq[v]=1; q.push(v); } } } } printf("%d\n",-d[mn]); } return 0; }
相关文章推荐
- 只会左键断点?是时候试试这样那样断点了
- 学习AngularJS的一些资料及网站
- E - 尤文图斯
- windows下如何将本地项目push到github仓库
- UVa 10340 All in All
- ubuntu 如何创建新用户
- zedboard 8路拨码开关
- PreparedStatement 预编译
- 安装及使用vsftpd+ssl
- 【网页访问单向、双向验证均可以】https原理及tomcat配置https方法[生成CA根证书配置tomcat后,若要成功访问axis中的webservice,需要配置它对应的axis2.xml文件]
- Windows2008 IIS配置FTP站点
- 敏捷开发Scrum
- hdoj 1276 士兵队列训练问题 【模拟】
- 机试算法讲解: 第37题 Dijkstra
- 贝格尔编排法代码
- 了解Objective-C中Selector基本概念和操作
- 绘制位图的两种方式
- Leetcode #233 Number of Digit One
- 机试算法讲解:第36题 Floyd
- centos 常用命令