POJ1089 Intervals
Description
Task
Write a program which:
reads from the std input the description of the series of intervals,
computes pairwise non−intersecting intervals satisfying the conditions given above,
writes the computed intervals in ascending order into std output
Input
Output
Sample Input
5
5 6
1 4
10 10
6 9
8 10
Sample Output
1 4
5 10
Source
//It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#ifdef WIN32
#define OT "%I64d"
#else
#define OT "%lld"
#endif
using namespace std;
typedef long long LL;
const int MAXN = ;
int n; struct seq{
int l,r;
}a[MAXN]; inline bool cmp(seq q,seq qq){ if(q.l==qq.l) return q.r<qq.r; return q.l<qq.l; } inline int getint()
{
int w=,q=;
char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar();
if (c=='-') q=, c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar();
return q ? -w : w;
} inline void solve(){
n=getint();
for(int i=;i<=n;i++) {
a[i].l=getint(); a[i].r=getint();
}
sort(a+,a+n+,cmp);
int nowl=a[].l,nowr=a[].r;
for(int i=;i<=n;i++) {
if(a[i].l>nowr) {
printf("%d %d\n",nowl,nowr);
nowl=a[i].l; nowr=a[i].r;
}
else if(a[i].r>nowr) nowr=a[i].r;
} printf("%d %d",nowl,nowr);
} int main()
{
solve();
return ;
}
POJ1089 Intervals的更多相关文章
- [LeetCode] Non-overlapping Intervals 非重叠区间
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
- [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- [LeetCode] Merge Intervals 合并区间
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...
- POJ1201 Intervals[差分约束系统]
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26028 Accepted: 9952 Descri ...
- Understanding Binomial Confidence Intervals 二项分布的置信区间
Source: Sigma Zone, by Philip Mayfield The Binomial Distribution is commonly used in statistics in a ...
- Leetcode Merge Intervals
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- LeetCode() Merge Intervals 还是有问题,留待,脑袋疼。
感觉有一点进步了,但是思路还是不够犀利. /** * Definition for an interval. * struct Interval { * int start; * int end; * ...
- Merge Intervals 运行比较快
class Solution { public: static bool cmp(Interval &a,Interval &b) { return a.start<b.star ...
- [LeetCode] 435 Non-overlapping Intervals
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
随机推荐
- $apply方法的作用
$apply方法是用来触发脏检查,它在控制器里监听一个变量,每当这个变量的值改变的时候,它会去与最初的值做一次比较,然后HTML页面就会及时更新该变量的值(将最新的值赋值到html页面的view层或M ...
- 关闭log4j 输出 DEBUG org.apache.commons.beanutils.*
2016-03-23 10:52:26,860 DEBUG org.apache.commons.beanutils.MethodUtils - Matching name=getEPort on c ...
- sqlalchemy 的 Core 方式使用示例
知乎: sqlalchemy 的 Core 方式操作数据是一种怎样的体验? 答: 爽! 本文基于:win 10 + python 3.4 + sqlalchemy 1.0.13 基本步骤如下: 1. ...
- 机器学习算法 Python & R速查表
- QuickFIX/J常见问题汇总
最近在搞QuickFIX/J,网上的资料不算很多,遇到一些简单的问题都需要google一阵才能找到解决方法,因此做点记录: 错误:Rejecting invalid message: quickfix ...
- CentOS 6.5系统安装配置图解教程
说明: 截止目前CentOS 6.x最新版本为CentOS 6.5,下面介绍CentOS 6.5的具体安装配置过程 服务器相关设置如下: 操作系统:CentOS 6.5 64位 IP地址:192.16 ...
- Android:30分钟弄明白Touch事件分发机制
Touch事件分发中只有两个主角:ViewGroup和View.Activity的Touch事件事实上是调用它内部的ViewGroup的Touch事件,可以直接当成ViewGroup处理. View在 ...
- WebSocket使用教程 2
WebSocket使用教程 - 带完整实例 收藏 james_laughing 发表于 2年前 阅读 46438 收藏 23 点赞 5 评论 4 摘要: WebSocket使用教程 - 带完整实例 什 ...
- JQuery学习笔记——JQuery基础
#,JQuery避免名称冲突的方法 var jq = jQuery.noConfilct(); jq.ready( function(){ jq("p").hidden() ...
- 从0开始学Java——JSP&Servlet——如何在Eclipse中配置Web容器为tomcat
windows- >Preferences -> Server->runtime Envirement ->Add 点击下一步,然后按照如下设置: