poj 1089 Intervals
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7214 | Accepted: 2862 |
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
#include<stdio.h> #include<string.h> #include<stdlib.h> #define N 50005 struct node { int c,d; }f[N]; int cmp(const void*a,const void*b) { if((*(struct node*)a).c==(*(struct node*)b).c) //从区间左端从小到大排序 return (*(struct node*)a).d>(*(struct node*)b).d?1:-1; //如果左端相等按右段排序 return (*(struct node*)a).c>(*(struct node*)b).c?1:-1; } int main() { int n,i; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%d%d",&f[i].c,&f[i].d); qsort(f,n,sizeof(f[0]),cmp); int a=f[0].c,b=f[0].d; for(i=1;i<n;i++) { if(f[i].c>b) //若区间不交叉,输出上一个区间 { printf("%d %d\n",a,b); a=f[i].c; b=f[i].d; } else if(b<f[i].d) b=f[i].d; //否则,判断当前右端是否大于上一区间的右端 } printf("%d %d\n",a,b); } return 0; }
poj 1089 Intervals的更多相关文章
- POJ 1089 Intervals【合并n个区间/贪心】
There is given the series of n closed intervals [ai; bi], where i=1,2,...,n. The sum of those interv ...
- poj 1201 Intervals 解题报告
Intervals Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Submit Statu ...
- POJ 3680 Intervals(费用流)
Intervals Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5762 Accepted: 2288 Descrip ...
- POJ 1201 Intervals (差分约束系统)
题意 在区间[0,50000]上有一些整点,并且满足n个约束条件:在区间[ui, vi]上至少有ci个整点,问区间[0, 50000]上至少要有几个整点. 思路 差分约束求最小值.把不等式都转换为&g ...
- poj 1201 Intervals(差分约束)
做的第一道差分约束的题目,思考了一天,终于把差分约束弄懂了O(∩_∩)O哈哈~ 题意(略坑):三元组{ai,bi,ci},表示区间[ai,bi]上至少要有ci个数字相同,其实就是说,在区间[0,500 ...
- poj 1201 Intervals(差分约束)
题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...
- POJ 1201 Intervals(图论-差分约束)
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20779 Accepted: 7863 Descri ...
- 图论(差分约束系统):POJ 1201 Intervals
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24099 Accepted: 9159 Descri ...
- 网络流(最大费用最大流) :POJ 3680 Intervals
Intervals Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7218 Accepted: 3011 Descrip ...
随机推荐
- HDU -1864最大报销额(01背包)
这道题属于简单的01背包,但是背包问题还算简单,就是前面的细节处理的时候要注意,题意大致说了三条限制吧 1. 只有a, b, c 三种类型的发票可以报销,其它的一律不报销 2. 物品单项的报销额不超过 ...
- ShareSDK.xml 配置
简要说明 <ShareSDK AppKey="1089fa233237e" /> <!-- 修改成你在sharesdk后台注册的应用的appkey" - ...
- 转 - Web新人(偏前端)应该怎样学习(个人观点,勿喷)
我自己是会计专业,转行自学web的,学习有一两年了,也还是新人一个,只不过不是那种超级“新”的,所以有什么话说得不对,请轻喷.欢迎大家来和我交流. 1.我能不能转行学web? 能不能学web这个不是别 ...
- The requested page cannot be accessed because the related configuration data for the page is invalid
当在VS2013下开发web site时,调试时都是在IIS Express中进行的,没有问题.当部署到IIS中,出现:The requested page cannot be accessed be ...
- img图片元素下多余空白解决方案
在进行页面的DIV+CSS排版时,遇到IE6(当然有时Firefox下也会偶遇)浏览器中的图片元素img下出现多余空白的问题绝对是常见的对於 该问题的解决方法也是「见机行事」,根据原因的不同要用不同的 ...
- div中实现居中
今天纠结了大半天的居中,把学到的先记录下来,还没完全弄清楚,发现网上原创的技术贴并不算多,大多都是相互转载.(ps.先安利一个大神的帖集,昨天才发现的,内容丰富,语言,呃...很幽默,一般都是图文并茂 ...
- css ie hack整理
网上有很多关于ie hack的文章,可能由于文章发布后ie的版本还在升级.所以导致有些hack写法已经不适用了.以下是本人整理的ie6-11的一些hack常用写法.(以下默认文档模式为标准模式) 1. ...
- new关键字在虚方法的动态调用中的阻断作用
关于new关键字在虚方法动态调用中的阻断作用,也有了更明确的理论基础.在子类方法中,如果标记 new 关键字,则意味着隐藏基类实现,其实就是创建了与父类同名的另一个方法,在编译中这两个方法处于动态方法 ...
- Swift中简单的单例设计
import Foundation class Test: NSObject { // 提供单例实例 static let shareInstance = Test() // 私有化构造方法 over ...
- Swift - 36 - 结尾闭包(Trailing closure)和捕获数值(Capturing Values)的简单介绍
//: Playground - noun: a place where people can play import UIKit // 初始化一个整数数组 var arr = [1, 3, 5, 7 ...