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 ...
随机推荐
- Renderer.materials
修改方法 meshBody.renderer.materials[].mainTexture= clothes[]; meshBody.renderer.materials[]=maters[]; 以 ...
- View (一)LayoutInflater()方法详解
相信接 触Android久一点的朋友对于LayoutInflater一定不会陌生,都会知道它主要是用于加载布局的.而刚接触Android的朋友可能对 LayoutInflater不怎么熟悉,因为加载布 ...
- C++中的运算符重载
首先思考以下几个问题: 1.什么是运算符重载? 2.为什么要重载运算符,它有什么用? 3.可以重载哪些运算符? 4.重载运算符有哪些规则? 一.基本概念 我们在程序中使用各种操作符,比如加(+).赋值 ...
- 详解反射->Type.System
反射先了解 一:system.Type 获取基本信息: Type.Name //类名 Type.FullName //完整路径 Type.Namespace //空间名 public class ...
- usb驱动开发1之学习准备
此系列是http://blog.csdn.net/fudan_abc/博文的整理,同时加入了自己的理解.很敬佩fudan_abc的文章,仔细学习和分析受益很多.注:fundan_abc所分析linux ...
- Python中的sort()方法使用基础
一.基本形式 sorted(iterable[, cmp[, key[, reverse]]]) iterable.sort(cmp[, key[, reverse]]) 参数解释: (1)itera ...
- Android View事件机制 21问21答
原文: http://www.cnblogs.com/punkisnotdead/p/5179115.html#3358859 1.View的坐标参数 主要有哪些?分别有什么注意的要点? 答:Left ...
- js copy
Javascript 实现复制(Copy)动作方法大全 投稿:hebedich 字体:[增加 减小] 类型:转载 时间:2014-06-20我要评论 现在浏览器种类也越来越多,诸如 IE.Firefo ...
- [CareerCup] 8.6 Jigsaw Puzzle 拼图游戏
8.6 Implement a jigsaw puzzle. Design the data structures and explain an algorithm to solve the puzz ...
- 启动页面设置,icon图标设置
更多尺寸像素如何放置请看:http://chicun.jammy.cc/ 如何设置App的启动图,也就是Launch Image? 新建一个iosLaunchImage文件夹