转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Integer Intervals
Time Limit: 1000MS   Memory Limit: 10000K

Description

An integer interval [a,b], a < b, is a set of all consecutive integers beginning with a and ending with b.
Write a program that: finds the minimal number of elements in a set
containing at least two different integers from each interval.

Input

The
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

Output the minimal number of elements in a set containing at least two different integers from each interval.

Sample Input

  1. 4
  2. 3 6
  3. 2 4
  4. 0 2
  5. 4 7

Sample Output

  1. 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[*MAXN];
  17. int head[MAXN];
  18. int e=;
  19. void init()
  20. {
  21. REP(i,MAXN)head[i]=-;
  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,);
  35. REP(i,MAXN)dis[i]=i==s?:INF;
  36. queue<int>q;
  37. q.push(s);
  38. vis[s]=;
  39. while(!q.empty())
  40. {
  41. int x=q.front();
  42. q.pop();
  43. int t=head[x];
  44. while(t!=-)
  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]=;
  54. q.push(y);
  55. }
  56. }
  57. vis[x]=;
  58. }
  59. }
  60. int main()
  61. {
  62. ios::sync_with_stdio(false);
  63. int n;
  64. int u,v,d;
  65. int ans=;
  66. int maxn=;
  67. int minn=MAXN;
  68. while(scanf("%d",&n)!= EOF&&n)
  69. {
  70. e=;
  71. init();
  72. REP(i,n)
  73. {
  74. scanf("%d%d",&u,&v);
  75. add_edge(u,v+,-);
  76. maxn=max(maxn,v+);
  77. minn=min(u,minn);
  78. }
  79. for(int i=minn;i<maxn;i++){
  80. add_edge(i+,i,);
  81. add_edge(i,i+,);
  82. }
  83. spfa(minn);
  84. cout<<-dis[maxn]<<endl;
  85. }
  86. return ;
  87. }

代码君

poj1716 Integer Intervals(差分约束)的更多相关文章

  1. poj 1716 Integer Intervals (差分约束 或 贪心)

    Integer Intervals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12192   Accepted: 514 ...

  2. POJ 1716 Integer Intervals 差分约束

    题目:http://poj.org/problem?id=1716 #include <stdio.h> #include <string.h> #include <ve ...

  3. POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束

    POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...

  4. POJ1201 Intervals(差分约束)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 10966 Description You ...

  5. hdu 1384 Intervals (差分约束)

    Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. zoj 1508 Intervals (差分约束)

    Intervals Time Limit: 10 Seconds      Memory Limit: 32768 KB You are given n closed, integer interva ...

  7. POJ 2101 Intervals 差分约束

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27746   Accepted: 10687 Description You ...

  8. poj 1201 Intervals(差分约束)

    题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...

  9. poj1201/zoj1508/hdu1384 Intervals(差分约束)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Intervals Time Limit: 10 Seconds      Mem ...

随机推荐

  1. 火狐Firefox 浏览器 onblur() 并且alert()时文本被选中问题

    说明:镜像是组成在线实验课程的基础环境,教师设计的实验绑定一个或多个镜像,就组成了一讲独立的在线实验课程. 镜像名称:     火狐Firefox 浏览器 onblur() 并且alert()时文本被 ...

  2. Phalcon自动加载(PHP自动加载)

    自动加载(phalcon\Loader) 转载请注明来源 一.php文件引入 通过 include() 或 require() 函数,可以在PHP程序执行之前在该文件中插入一个文件的内容. 区别:处理 ...

  3. 搭建MHA环境【1】规划+linux相关的设置

    [1]规划 MHA这套软件包涵两个部分 1.manager :主要负责对MySQL集群状态的检查&在master 库宕机时对故障进行转移. 2.node      :主要包涵状态检查& ...

  4. Linux怎样修改系统时间

    修改linux的时间可以使用date指令 修改日期: 时间设定成2009年5月10日的命令如下: #date -s 05/10/2009 修改时间: 将系统时间设定成上午10点18分0秒的命令如下. ...

  5. XJOI网上同步训练DAY1 T1

    思路:我们考虑由于没有人的区间会覆盖其他人,所以我们将区间按左端点排序,发现如果地盘长度已知,可以贪心地尽量往左放,来判断是否有解,因此做法很简单,就是二分答案,然后O(n)贪心判定,复杂度为O(nl ...

  6. PowerShell_零基础自学课程_2_Powershell与Cmd以及Unix/Linux Shell

    上篇文章我说道,windows为了改变用户对其console界面的诟病,于是就从windows   vista开始,计划要改变这种局面,于是就有 了Powershell的出现. 1.兼容shell命令 ...

  7. linux下ifconfig, DNS以及route配置

    转载:http://blog.csdn.net/wangjingfei/article/details/5283632/ 熟悉使用ifconfig 会非常方便. ifconfig eth0 新ip 然 ...

  8. perl 对象 通过bless实现

    对象只是一种特殊的引用,它知道自己是和哪个类关联在一起的,而构造器知道如何创建那种关联关系. 这些构造器是通过使用bless操作符,将一个普通的引用物转换成一个对象实现的,

  9. Poj3468-A Simple Problem with Integers(伸展树练练手)

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  10. ios相册

    1, 系统图片剪裁的问题 http://www.cnblogs.com/liulunet/archive/2013/01/19/2866399.html