Integer Intervals
描述
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相关推荐
- 21:Integer Intervals
21:Integer Intervals 描述 An integer interval [a,b], a < b, is a set of all consecutive integers be ...
- POJ 1716 Integer Intervals【差分约束】
题意: 知道了数轴上的n个区间,每个区间都是连续的int区间,现在要在数轴上任意取一堆元素,构成一个元素集合V要求每个区间和元素集合V的交集至少有两个不同的元素 求集合V最小的元素个数. 转一分析:( ...
- POJ 1716 Integer Intervals 差分约束
题目:http://poj.org/problem?id=1716 1 #include <stdio.h> 2 #include <string.h> 3 #include ...
- POJ 1716 Integer Intervals
POJ_1716 由于有了前面几个题目的基础,解答这个题目的过程还算顺利.我们设S[i]为区间[0,i)内选取的数字的数量,那么有①S[b+1]-S[a]>=2,②S[i+1]-S[i]> ...
- 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 ...
- 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 ...
- 投入OJ的怀抱~~~~~~~~~~
OpenJudge C20182024 信箱(1) 账号 修改设定 退出小组 管理员 frank 林舒 Dzx someone 李文新 公告 11-05 程序设计与算法(大学先修课) 成员(61910 ...
- Interval (mathematics)
In mathematics, a (real) interval is a set of real numbers that contains all real numbers lying betw ...
最新文章
- 微信授权登录提示不能访问?
- bootstrap3中select2的默认值和下拉框的禁用
- JAVA JDK环境渲染
- 10 人,2 个月 | 虾米音乐的监控体系升级之路
- java解析xml 字符串_Java解析XML字符串
- vue webpack打包后图片路径错误的解决方法
- webpack5+vue3搭建h5项目模板-(一)-基础配置
- 优秀的人真是“自律”吗? —— 《微习惯》读后感
- C语言函数:even(n),fflush(stdin)
- 【有奖征询】可查询商票及企业境外债软件有奖征询
- [小技巧] git: Your branch and 'origin/master' have diverged
- 易用的项目进度管理软件推荐
- 点云旋转平移(三)—python open3d点云旋转
- 分布式搜索引擎ElasticSearch之高级运用(三)
- linux 定时开关机
- 小可爱怎么备份word自动图文集呢?
- Lua系列--pairs和ipairs
- 深深的思考与共鸣——资源共享
- 研发人员绩效评价常见误区
- 富文本编辑vue插件vue-quill-editor
热门文章
- ADB logcat调试和端口占用解决办法
- c语言(1%3c%3cn),JavaScript教程 一段鬼畜风格的JavaScript解密
- 硬盘分区那点事儿(MBR和GPT)
- Unity 3D PC平台发布|| Unity 3D Web 平台发布||Unity 3D Android平台发布
- 大数据量的五种处理方式
- 在中国做量化交易一天的工作内容
- 易语言进程通信c语言,易语言进程通信模块和例程源码
- linux让前台程序脱离终端运行
- 微型计算机出现在20世纪,北语网院20秋《计算机基础》作业【标准答案】
- ubuntu下街机模拟器 mame 安装和玩拳王97