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 ...
随机推荐
- 95秀-自定义对话框 dialog 合集
普通的确认对话框 NormalDialog.java import android.app.Dialog; import android.content.Context; import android ...
- 我对Backbone中url属性的理解
Model中有一个url属性,而且有一个urlRoot属性. Collection中也有一个url属性. // 这是Model中的url方法 url: function() { var base = ...
- Linux升级C基本运行库CLIBC
在你准备升级GLIBC库之前,你要好好思考一下, 你真的要升级GLIBC么? 你知道你自己在做什么么? glibc是gnu发布的libc库,即c运行库.glibc是linux系统中最底层的api,几乎 ...
- Struts2 模型驱动及页面回显
* 要从页面中获取表单元素的值,需要在动作类中声明与页面元素同名的属性.导致动作类中既有javabean又有业务方法. * 将javabean和业务方法进行分离: * 将重 ...
- Date与Calendar
Date date=new Date();//现在时间 Date date1=new Date(1000);//格林威治时间1997/01/01开始算,后面的是毫秒 Calendar calendar ...
- 迭代器(iterator) 与 traits 编程技法
看了候哥的<STL源码剖析>的迭代器那一章,在这里将思路稍微疏理一下 迭代器 迭代器模式的定义:提供一种方法,在不需要暴露某个容器的内部表现形式情况下,使之能依次访问该容器中的各个元素. ...
- 转:初学者,手工注入测试方法小节 (出处:: 51Testing软件测试网--jie)
1.加入单引号 ’提交, 结果:如果出现错误提示,则该网站可能就存在注入漏洞. 2.数字型判断是否有注入; 语句:and 1=1 ;and 1=2 (经典).' and '1'=1(字符型) ...
- SSM框架搭建java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
在搭建 spring springMVC Mybatis 时候出错 将org.springframework.http.converter.json.MappingJacksonHttpMessage ...
- 关于 Delphi 中的Sender和易混淆的概念(转)
/////////////////////////////////////////////////////// Delphi 中Sender对象的定义///////////////////////// ...
- 标签static
静态文本控件的功能比较简单,可作为显示字符串,图标,位图用.创建一个窗口可以使用成员函数: BOOL CStatic::Create( LPCTSTR lpszText, DWORD dwStyle, ...