poj1716 Integer Intervals(差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Time Limit: 1000MS | Memory Limit: 10000K |
Description
Write a program that: finds the minimal number of elements in a set containing at least two different integers from each interval.
Input
Output
Sample Input
4 3 6 2 4 0 2 4 7
Sample Output
4
上一题差分约束的阉割版(传送门)
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <queue> 7 using namespace std; 8 typedef long long ll; 9 typedef pair<int,int> PII; 10 #define MAXN 50010 11 #define REP(A,X) for(int A=0;A<X;A++) 12 #define INF 0x7fffffff 13 #define CLR(A,X) memset(A,X,sizeof(A)) 14 struct node { 15 int v,d,next; 16 }edge[3*MAXN]; 17 int head[MAXN]; 18 int e=0; 19 void init() 20 { 21 REP(i,MAXN)head[i]=-1; 22 } 23 void add_edge(int u,int v,int d) 24 { 25 edge[e].v=v; 26 edge[e].d=d; 27 edge[e].next=head[u]; 28 head[u]=e; 29 e++; 30 } 31 bool vis[MAXN]; 32 int dis[MAXN]; 33 void spfa(int s){ 34 CLR(vis,0); 35 REP(i,MAXN)dis[i]=i==s?0:INF; 36 queue<int>q; 37 q.push(s); 38 vis[s]=1; 39 while(!q.empty()) 40 { 41 int x=q.front(); 42 q.pop(); 43 int t=head[x]; 44 while(t!=-1) 45 { 46 int y=edge[t].v; 47 int d=edge[t].d; 48 t=edge[t].next; 49 if(dis[y]>dis[x]+d) 50 { 51 dis[y]=dis[x]+d; 52 if(vis[y])continue; 53 vis[y]=1; 54 q.push(y); 55 } 56 } 57 vis[x]=0; 58 } 59 } 60 int main() 61 { 62 ios::sync_with_stdio(false); 63 int n; 64 int u,v,d; 65 int ans=0; 66 int maxn=0; 67 int minn=MAXN; 68 while(scanf("%d",&n)!= EOF&&n) 69 { 70 e=0; 71 init(); 72 REP(i,n) 73 { 74 scanf("%d%d",&u,&v); 75 add_edge(u,v+1,-2); 76 maxn=max(maxn,v+1); 77 minn=min(u,minn); 78 } 79 for(int i=minn;i<maxn;i++){ 80 add_edge(i+1,i,1); 81 add_edge(i,i+1,0); 82 } 83 spfa(minn); 84 cout<<-dis[maxn]<<endl; 85 } 86 return 0; 87 }
代码君
转载于:https://www.cnblogs.com/fraud/p/4304409.html
poj1716 Integer Intervals(差分约束)相关推荐
- POJ 1716 Integer Intervals 差分约束
题目:http://poj.org/problem?id=1716 1 #include <stdio.h> 2 #include <string.h> 3 #include ...
- poj1201/zoj1508/hdu1384 Intervals(差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ --by fraud Intervals Time Limit: 10 Seconds Me ...
- poj-1201 Intervals(差分约束)
题目链接: Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24379 Accepted: 9274 ...
- poj 1201 Intervals 差分约束
真 .读题杀,英文题一脸懵逼,看来以后还要多读读英文题,不过读完了就能发现这其实是一道很裸的差分约束,按照题意建边即可,但还要注意的就是后一个要大于等于前一个,并且每个位置不能超过一个元素.求一边最大 ...
- POJ - 1201 Intervals(差分约束+最短路)
题目链接:点击查看 题目大意:给定n个闭区间[ai,bi]和n个整数ci,你需要构造一个整数集合Z,使得Z中满足所有的ai<=x<=bi的整数不少于ci个,求出这样的整数集合Z最少包含多少 ...
- POJ 1716 Integer Intervals【差分约束】
题意: 知道了数轴上的n个区间,每个区间都是连续的int区间,现在要在数轴上任意取一堆元素,构成一个元素集合V要求每个区间和元素集合V的交集至少有两个不同的元素 求集合V最小的元素个数. 转一分析:( ...
- poj1716(差分约束+SPFA)
题意:整数间隔[a,b],a<b,是以a开头和以b结尾的所有连续整数的集合.在包含至少两个不同整数的集合中找到每个间隔的最小元素数. 思路:采用差分约束算法:当问题可以转化为形如一组 xi‑x' ...
- POJ 1201 amp; HDU1384 amp; ZOJ 1508 Intervals(差分约束+spfa 求最长路径)
题目链接: POJ:http://poj.org/problem?id=1201 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1384 ZOJ:htt ...
- 差分约束 1:pku 1201 Intervals 2:pku 1364 King 3:hdu 1534
一个很好的差分约束总结:http://972169909-qq-com.iteye.com/blog/1185527 第一: 感觉难点在于建图 第二: ①:对于差分不等式,a - b <= ...
- HDU 1384 Intervals【差分约束-SPFA】
类型:给出一些形如a−b<=k的不等式(或a−b>=k或a−b<k或a−b>k等),问是否有解[是否有负环]或求差的极值[最短/长路径]. 例子:b−a<=k1,c−b& ...
最新文章
- 为什么没有MMU的处理器无法安装操作系统?
- htaccess分布式配置文件常用写法
- mysql5.6.40升级到mysql8.0.11 的步骤
- SAP评估级别 Valuation Area
- 电脑看书软件_能全平台阅读的图书软件,是kindle? No!大公司低调出品
- Qt Creator调试Qt Quick示例应用程序
- BZOJ2809 dispatching 【可并堆】
- php pfm 改端口,罗马2ESF和PFM 修改建筑 军团 派系 兵种等等等很多东西的教程
- 【JavaWeb】JDBC的基本操作和事务控制+登录和转账案例
- springboot报错Table 'wechat.hibernate_sequence' doesn't exist
- git merge 回退_git+vscode进行版本控制
- 思科路由器Ez***解决地址重叠测试
- A New Romance Is Likely to End up like Your Previous Relationship 为什么每次恋爱总会走向相似的结局?
- 30个ies光域网带图_15个让你脚下更细腻的经典控球训练
- matlab定义变量var,设置变量数据类型 - MATLAB setvartype
- MathWorks 中国
- 斯皮尔曼相关系数范围_Spearman Rank(斯皮尔曼等级)相关系数
- Topaz Video Enhance Al视频无损放大软件常见问题指南
- Java 代理使用详解
- android-自定义锁屏界面
- e1载波的数据速率是_Wi-Fi 6(802.11ax)解析25:DCM双载波调制技术