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 ...
随机推荐
- android调试模拟器启动太慢,怎样才能更快的调试程序呢?
答: 1. 模拟器不关,直接按调试按钮系统会自动重新安装软件的.
- iOS数组使用
相关链接: ios数组基本用法和排序 NSArray 排序汇总 iOS 数组排序方法 IOS-筛选数组内的元素 关于EnumerateObjectsUsingBlock和for-in之间的较量 [iO ...
- Android应用开发中如何使用隐藏API(转)
一开始需要说明的是,Google之所以要将一些API隐藏(指加上@hide标记的public类.方法或常量)是有原因的.其中很大的原因就是Android系统本身还在不断的进化发展中.从1.0.1.1到 ...
- 自定义WPF ListBox的选中项样式
首先介绍一种简单地方法:就是通过自定义SystemColors类的参数来自定义WPF ListBox选择颜色的,SystemColors的HighlightBrushKey和HighlightText ...
- [转]iptables详解
FROM : http://blog.chinaunix.net/uid-26495963-id-3279216.html 一:前言 防火墙,其实说白了讲,就是用于实现Linux下访问控制的功能的 ...
- Linux Linux程序练习十一(网络编程大文件发送UDP版)
//网络编程发送端--大文件传输(UDP) #include <stdio.h> #include <stdlib.h> #include <string.h> # ...
- no.1
#import requests import urllib import bs4 try: html=urllib.urlopen('http://anyun.org') except HTTPer ...
- Enabling CORS in WCF
Introduction This is an intermediate example of WCF as REST based solution and enabling CORS access, ...
- Linux及安全——模块
Linux及安全——模块 一.模块的编译.生成.测试.删除 1.编写模块代码 编写:gedit test.c 查看:cat test.c 2.查看版本信息 3.编写Makefile obj-m :这个 ...
- 树莓派之web服务器搭建
树莓派之web服务器搭建 (一)使用ufw创建防火墙 设置目的:可以完全阻止对树莓派的访问也可以用来配置通过防火墙对特点程序的访问.使用防火墙更好的保护树莓派. 准备工作 1.带有5V电源的树莓派 2 ...