标签:answer lines 不等式 return miss sha ever print cst
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=1384
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4841 Accepted Submission(s): 1815
#include <iostream> #include <cstdio> #include<stdio.h> #include<algorithm> #include<cstring> #include<math.h> #include<memory> #include<queue> #include<vector> using namespace std; #define max_v 50010 #define INF 9999999 int tot; int head[max_v]; int vis[max_v]; int dis[max_v]; int minn,maxx; struct node { int u,v,val; int next; }Edge[max_v<<2]; void addEdge(int u,int v,int val) { Edge[tot].u=u; Edge[tot].v=v; Edge[tot].val=val; Edge[tot].next=head[u]; head[u]=tot++; } void spfa() { for(int i=minn-1;i<=maxx;i++) dis[i]=-INF; queue<int> q; dis[maxx]=0; vis[maxx]=1; q.push(maxx); while(!q.empty()) { int u=q.front(); q.pop(); vis[u]=0; for(int i=head[u];i!=-1;i=Edge[i].next) { int v=Edge[i].v; if(dis[v]<dis[u]+Edge[i].val) { dis[v]=dis[u]+Edge[i].val; if(!vis[v]) { vis[v]=1; q.push(v); } } } } printf("%d\n",dis[minn-1]); return ; } int main() { int n,a,b,c; while(~scanf("%d",&n)) { tot=0; memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); maxx=0; minn=INF; for(int i=0;i<n;i++) { scanf("%d %d %d",&a,&b,&c); a++; b++; minn=min(minn,a); maxx=max(maxx,b); addEdge(b,a-1,c); } for(int i=minn;i<=maxx;i++) { addEdge(i,i-1,0); addEdge(i-1,i,-1); } spfa(); } return 0; }
POJ 1384 Intervals (线性差分约束,根据不等式建图,然后跑spfa)
标签:answer lines 不等式 return miss sha ever print cst
原文地址:https://www.cnblogs.com/yinbiao/p/9445855.html