描述

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.

输入

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 the minimal number of elements in a set containing at least two different integers from each interval.

样例输入

4
3 6
2 4
0 2
4 7

样例输出

4
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#define sf(a) scanf("%d\n",&a)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define e 1e-8
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int idata=1e4+5;int i,j,k;
int judge,flag,temp;
//vector<ll>step(idata);
ll step[idata];
//int dp[idata];
ll n,m,t,x,y;
ll maxx=-inf,minn=inf;
ll cnt,len,ans,sum;
int l[idata],r[idata];
pair<int ,int>p[idata];
string s;
int cmp[100000];int main()
{while(cin>>n){for(i=1;i<=n;i++){cin>>l[i]>>r[i];p[i].first=r[i];p[i].second=l[i];}sort(p+1,p+1+n);int left=p[1].first-1;int right=p[1].first;sum=2;for(i=2;i<=n;i++){if(p[i].second>right){sum+=2;left=p[i].first-1;right=left+1;}else if(right>=p[i].second&&left<p[i].second){sum++;left=right;right=p[i].first;}}cout<<sum<<endl;}return 0;
}

Integer Intervals相关推荐

  1. 21:Integer Intervals

    21:Integer Intervals 描述 An integer interval [a,b], a < b, is a set of all consecutive integers be ...

  2. POJ 1716 Integer Intervals【差分约束】

    题意: 知道了数轴上的n个区间,每个区间都是连续的int区间,现在要在数轴上任意取一堆元素,构成一个元素集合V要求每个区间和元素集合V的交集至少有两个不同的元素 求集合V最小的元素个数. 转一分析:( ...

  3. POJ 1716 Integer Intervals 差分约束

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

  4. POJ 1716 Integer Intervals

    POJ_1716 由于有了前面几个题目的基础,解答这个题目的过程还算顺利.我们设S[i]为区间[0,i)内选取的数字的数量,那么有①S[b+1]-S[a]>=2,②S[i+1]-S[i]> ...

  5. 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 ...

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

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

  7. poj-1201 Intervals(差分约束)

    题目链接: Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24379   Accepted: 9274 ...

  8. 投入OJ的怀抱~~~~~~~~~~

    OpenJudge C20182024 信箱(1) 账号 修改设定 退出小组 管理员 frank 林舒 Dzx someone 李文新 公告 11-05 程序设计与算法(大学先修课) 成员(61910 ...

  9. Interval (mathematics)

    In mathematics, a (real) interval is a set of real numbers that contains all real numbers lying betw ...

最新文章

  1. 微信授权登录提示不能访问?
  2. bootstrap3中select2的默认值和下拉框的禁用
  3. JAVA JDK环境渲染
  4. 10 人,2 个月 | 虾米音乐的监控体系升级之路
  5. java解析xml 字符串_Java解析XML字符串
  6. vue webpack打包后图片路径错误的解决方法
  7. webpack5+vue3搭建h5项目模板-(一)-基础配置
  8. 优秀的人真是“自律”吗? —— 《微习惯》读后感
  9. C语言函数:even(n),fflush(stdin)
  10. 【有奖征询】可查询商票及企业境外债软件有奖征询
  11. [小技巧] git: Your branch and 'origin/master' have diverged
  12. 易用的项目进度管理软件推荐
  13. 点云旋转平移(三)—python open3d点云旋转
  14. 分布式搜索引擎ElasticSearch之高级运用(三)
  15. linux 定时开关机
  16. 小可爱怎么备份word自动图文集呢?
  17. Lua系列--pairs和ipairs
  18. 深深的思考与共鸣——资源共享
  19. 研发人员绩效评价常见误区
  20. 富文本编辑vue插件vue-quill-editor

热门文章

  1. ADB logcat调试和端口占用解决办法
  2. c语言(1%3c%3cn),JavaScript教程 一段鬼畜风格的JavaScript解密
  3. 硬盘分区那点事儿(MBR和GPT)
  4. Unity 3D PC平台发布|| Unity 3D Web 平台发布||Unity 3D Android平台发布
  5. 大数据量的五种处理方式
  6. 在中国做量化交易一天的工作内容
  7. 易语言进程通信c语言,易语言进程通信模块和例程源码
  8. linux让前台程序脱离终端运行
  9. 微型计算机出现在20世纪,北语网院20秋《计算机基础》作业【标准答案】
  10. ubuntu下街机模拟器 mame 安装和玩拳王97