HDU 1384 Intervals (差分约束)
来源:互联网 发布:淘宝店铺电脑怎么激活 编辑:程序博客网 时间:2024/05/16 07:26
Sample Input
53 7 38 10 36 8 11 3 110 11 1
Sample Output
6
题意:给你n个数u,v,w;要求在[u,v]区间至少取w个数(整数),求最少要取多少个数。
S[v+1] - S[u] >= w, S[i+1] - S[i] >=0&&<=1,S[i] - S[i+1] <=-1.
在u,v+1之间建一条边,跑一遍SPFA即可。
#include <iostream>#include <stdio.h>#include <string.h>#include<string>#include<math.h>#include<queue>#include<stack>#include <algorithm>#include<vector>#include<map>using namespace std;#define M 100#define inf 0x3fffffff#define maxn 50005#define ll long longstruct edge{int v,num,next;}e[maxn*4];int edge_num,a,b,vis[maxn],d[maxn];int head[maxn];void add(int a,int b,int c){e[edge_num].num=b;e[edge_num].v=c;e[edge_num].next=head[a];head[a]=edge_num++;}int n;void SPFA(){queue<int>q;memset(vis,0,sizeof(vis));memset(d,-50005,sizeof(d));/*for(int i=a;i<=b;i++)d[i]=-50005;*/while(!q.empty()) q.pop();q.push(a);d[a]=0;vis[a]=1;while(!q.empty()){int u=q.front();q.pop();for(int i=head[u];i!=-1;i=e[i].next){int v=e[i].num;if(d[v]<d[u]+e[i].v){d[v]=d[u]+e[i].v;if(!vis[v]){q.push(v);vis[v]=1;}}}vis[u]=0;}}int main(){while(~scanf("%d",&n)){edge_num=0;memset(head,-1,sizeof(head));int u,v,w;a=inf,b=0;while(n--){scanf("%d%d%d",&u,&v,&w);if(u<a)a=u;if(v+1>b)b=v+1;add(u,v+1,w);}for(int i=a;i<b;i++){add(i+1,i,-1);add(i,i+1,0);}SPFA();printf("%d\n",d[b]);}return 0;}
0 0
- HDU 1384 Intervals(差分约束)
- HDU 1384 Intervals (差分约束)
- hdu 1384 Intervals 差分约束
- HDU 1384 Intervals 差分约束
- 【HDU】1384 Intervals 差分约束系统
- hdu 1384 Intervals (差分约束)
- hdu 1384 Intervals 差分约束系统
- hdu 1384 Intervals 差分约束 + Bellman(附SPAF)
- POJ 1201 && HDU 1384 Intervals(差分约束系统)
- hdoj--1384--Intervals(差分约束)
- Intervals (差分约束)
- HDU 1384 && POJ 1201--Intervals 【基础差分约束】
- POJ 1201 && HDU 1384Intervals 差分约束系统
- POJ 1201/hdu 1384 Intervals【差分约束+SPFA】
- hdu 1384 Intervals 差分约束 解题报告
- Intervals(差分约束)
- 【差分约束】 HDOJ 1384 Intervals
- HDOJ 题目1384 Intervals(差分约束)
- C++ 重载 覆盖和隐藏
- Kafka 体系结构
- jquery重新播放css动画
- Java 中数据类型转换成 byte[] 方法
- apahce2.4.6在windows下的基本配置
- HDU 1384 Intervals (差分约束)
- python的问题
- 【9月计划】
- 看到了很不错的css3 animation的教程
- STK 《Connect命令参考手册》首发
- Phonegap2.9.0本地打包html成ios应用
- Android 自定义控件之界面标题导航及控件打包共享
- PhoneGap2.9.0本地将html打包成Android应用
- ios UIWebView截获html并修改便签内容