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 ...
随机推荐
- JavaScript代码性能优化总结
JavaScript 代码性能优化总结 尽量使用源生方法 javaScript是解释性语言,相比编译性语言执行速度要慢.浏览器已经实现的方法,就不要再去实现一遍了.另外,浏览器已经实现的方法在算法方面 ...
- Socket服务端口长连接最多能支持多少?
答案是无限的.视服务端的资源而不同. 以前一直认为服务端在Accept客户端连接后,会开启一个新的端口与客户端建立链路,但这是错误的.事实上,一个连路是由Server IP+server Port + ...
- java 格式判断
public class FormatChecker { /** * 判断是否含有汉字 * @param string */ public static boolean containChinese( ...
- 进阶C#?
玩了几年的编程了,大四了.本来不想考研,我老师找我谈几次,最近准备考研.从一开始玩java,接触.net中的C#,aps.net,到接触linux,太多太多了. 本来我们专业不是纯计算机的,但是和计算 ...
- [转]链接分析算法之:主题敏感PageRank
原文引自:http://blog.csdn.net/hguisu/article/details/8005192,感谢 前面的讨论提到.PageRank忽略了主题相关性,导致结果的相关性和主题性降低, ...
- [转]C++堆和栈的区别
一.预备知识―程序的内存分配 一个由c/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)― 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈. ...
- MySQL查询优化处理
查询的生命周期的下一步是将一个sql转化成一个执行计划,MySQL再依照这个执行计划和存储引擎进行交互.这包括多个子阶段:解析sql,预处理,优化sql执行计划.这个过程中任何错误(例如语法错误)都可 ...
- jQuery制作go to top按钮
转自:http://www.w3cplus.com/jquery/scrolling-to-the-top-with-jquery 每每看到网友Blog的页面底部或中间有一个按钮回到页面顶部,羡慕死人 ...
- Java泛型的基本应用
一.泛型概述 jdk1.5版本以后出现的新特性,用于解决安全问题,是一个安全机制. 好处: 1,将运行时期的问题ClassCastException转到了编译时期. 2,避免了强制转换的麻烦. 什么时 ...
- C++ AO读取shapefile的属性值
C++ AO读取一个shapefile文件的所有属性值 #include "stdafx.h" #include "iostream.h" #inc ...