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
first line of the input contains the number of intervals n, 1 <= n
<= 10000. Each of the following n lines contains two integers a, b
separated by a single space, 0 <= a < b <= 10000. They are the
beginning and the end of an interval.
Output
Sample Input
- 4
- 3 6
- 2 4
- 0 2
- 4 7
Sample Output
- 4
上一题差分约束的阉割版(传送门)
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <cstdlib>
- #include <algorithm>
- #include <queue>
- using namespace std;
- typedef long long ll;
- typedef pair<int,int> PII;
- #define MAXN 50010
- #define REP(A,X) for(int A=0;A<X;A++)
- #define INF 0x7fffffff
- #define CLR(A,X) memset(A,X,sizeof(A))
- struct node {
- int v,d,next;
- }edge[*MAXN];
- int head[MAXN];
- int e=;
- void init()
- {
- REP(i,MAXN)head[i]=-;
- }
- void add_edge(int u,int v,int d)
- {
- edge[e].v=v;
- edge[e].d=d;
- edge[e].next=head[u];
- head[u]=e;
- e++;
- }
- bool vis[MAXN];
- int dis[MAXN];
- void spfa(int s){
- CLR(vis,);
- REP(i,MAXN)dis[i]=i==s?:INF;
- queue<int>q;
- q.push(s);
- vis[s]=;
- while(!q.empty())
- {
- int x=q.front();
- q.pop();
- int t=head[x];
- while(t!=-)
- {
- int y=edge[t].v;
- int d=edge[t].d;
- t=edge[t].next;
- if(dis[y]>dis[x]+d)
- {
- dis[y]=dis[x]+d;
- if(vis[y])continue;
- vis[y]=;
- q.push(y);
- }
- }
- vis[x]=;
- }
- }
- int main()
- {
- ios::sync_with_stdio(false);
- int n;
- int u,v,d;
- int ans=;
- int maxn=;
- int minn=MAXN;
- while(scanf("%d",&n)!= EOF&&n)
- {
- e=;
- init();
- REP(i,n)
- {
- scanf("%d%d",&u,&v);
- add_edge(u,v+,-);
- maxn=max(maxn,v+);
- minn=min(u,minn);
- }
- for(int i=minn;i<maxn;i++){
- add_edge(i+,i,);
- add_edge(i,i+,);
- }
- spfa(minn);
- cout<<-dis[maxn]<<endl;
- }
- return ;
- }
代码君
poj1716 Integer Intervals(差分约束)的更多相关文章
- poj 1716 Integer Intervals (差分约束 或 贪心)
Integer Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12192 Accepted: 514 ...
- POJ 1716 Integer Intervals 差分约束
题目:http://poj.org/problem?id=1716 #include <stdio.h> #include <string.h> #include <ve ...
- POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束
POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...
- POJ1201 Intervals(差分约束)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 10966 Description You ...
- hdu 1384 Intervals (差分约束)
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- zoj 1508 Intervals (差分约束)
Intervals Time Limit: 10 Seconds Memory Limit: 32768 KB You are given n closed, integer interva ...
- POJ 2101 Intervals 差分约束
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 27746 Accepted: 10687 Description You ...
- poj 1201 Intervals(差分约束)
题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...
- poj1201/zoj1508/hdu1384 Intervals(差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Intervals Time Limit: 10 Seconds Mem ...
随机推荐
- 火狐Firefox 浏览器 onblur() 并且alert()时文本被选中问题
说明:镜像是组成在线实验课程的基础环境,教师设计的实验绑定一个或多个镜像,就组成了一讲独立的在线实验课程. 镜像名称: 火狐Firefox 浏览器 onblur() 并且alert()时文本被 ...
- Phalcon自动加载(PHP自动加载)
自动加载(phalcon\Loader) 转载请注明来源 一.php文件引入 通过 include() 或 require() 函数,可以在PHP程序执行之前在该文件中插入一个文件的内容. 区别:处理 ...
- 搭建MHA环境【1】规划+linux相关的设置
[1]规划 MHA这套软件包涵两个部分 1.manager :主要负责对MySQL集群状态的检查&在master 库宕机时对故障进行转移. 2.node :主要包涵状态检查& ...
- Linux怎样修改系统时间
修改linux的时间可以使用date指令 修改日期: 时间设定成2009年5月10日的命令如下: #date -s 05/10/2009 修改时间: 将系统时间设定成上午10点18分0秒的命令如下. ...
- XJOI网上同步训练DAY1 T1
思路:我们考虑由于没有人的区间会覆盖其他人,所以我们将区间按左端点排序,发现如果地盘长度已知,可以贪心地尽量往左放,来判断是否有解,因此做法很简单,就是二分答案,然后O(n)贪心判定,复杂度为O(nl ...
- PowerShell_零基础自学课程_2_Powershell与Cmd以及Unix/Linux Shell
上篇文章我说道,windows为了改变用户对其console界面的诟病,于是就从windows vista开始,计划要改变这种局面,于是就有 了Powershell的出现. 1.兼容shell命令 ...
- linux下ifconfig, DNS以及route配置
转载:http://blog.csdn.net/wangjingfei/article/details/5283632/ 熟悉使用ifconfig 会非常方便. ifconfig eth0 新ip 然 ...
- perl 对象 通过bless实现
对象只是一种特殊的引用,它知道自己是和哪个类关联在一起的,而构造器知道如何创建那种关联关系. 这些构造器是通过使用bless操作符,将一个普通的引用物转换成一个对象实现的,
- Poj3468-A Simple Problem with Integers(伸展树练练手)
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
- ios相册
1, 系统图片剪裁的问题 http://www.cnblogs.com/liulunet/archive/2013/01/19/2866399.html