uva 10020 Minimal coverage
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=961
贪心,排序,对左端点贪,找最大右端点。
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #define maxn 6000000
- using namespace std;
- int t,m;
- int t1;
- int ll[maxn],rr[maxn];
- struct node
- {
- int l,r;
- int id;
- bool operator <(const node &a)const
- {
- return (l<a.l)||(l==a.l&&r>a.r);
- }
- } p[maxn],ans[maxn];
- int main()
- {
- scanf("%d",&t);
- while(t--)
- {
- t1=;
- scanf("%d",&m);
- int cnt=;
- int l,r;
- int num=;
- while(scanf("%d%d",&l,&r)!=EOF)
- {
- if(l==&&r==) break;
- if(l>m||r<) continue;
- p[cnt].id=num;
- p[cnt].l=l;
- p[cnt++].r=r;
- }
- sort(p,p+cnt);
- bool flag1=false;
- int ll=,rr=;
- while()
- {
- if(ll>=m)
- {
- break;
- }
- flag1=false;
- rr=;
- int pos;
- for(int i=; i<cnt; i++)
- {
- if(p[i].l<=ll&&p[i].r>rr)
- {
- pos=i;
- rr=p[i].r;
- flag1=true;
- }
- }
- if(flag1)
- {
- t1++;
- ans[t1]=p[pos];
- ll=rr;
- }
- else break;
- }
- if(flag1)
- {
- printf("%d\n",t1);
- for(int i=; i<=t1; i++)
- {
- printf("%d %d\n",ans[i].l,ans[i].r);
- }
- }
- else printf("0\n");
- }
- return ;
- }
uva 10020 Minimal coverage的更多相关文章
- 【区间覆盖问题】uva 10020 - Minimal coverage
可以说是区间覆盖问题的例题... Note: 区间包含+排序扫描: 要求覆盖区间[s, t]; 1.把各区间按照Left从小到大排序,如果区间1的起点大于s,则无解(因为其他区间的左起点更大):否则选 ...
- UVA 10020 Minimal coverage(贪心 + 区间覆盖问题)
Minimal coverage The Problem Given several segments of line (int the X axis) with coordinates [Li, ...
- uva 10020 Minimal coverage 【贪心】+【区间全然覆盖】
Minimal coverage The Problem Given several segments of line (int the X axis) with coordinates [Li,Ri ...
- uva.10020 Minimal coverage(贪心)
10020 Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose t ...
- UVa 10020 - Minimal coverage(区间覆盖并贪心)
Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the min ...
- 贪心 URAL 1303 Minimal Coverage
题目传送门 /* 题意:最少需要多少条线段能覆盖[0, m]的长度 贪心:首先忽略被其他线段完全覆盖的线段,因为选取更长的更优 接着就是从p=0开始,以p点为标志,选取 (node[i].l < ...
- UVA-10020 Minimal coverage(贪心)
题目大意:在x轴上,给一些区间,求出能把[0,m]完全覆盖的最少区间个数及该情形下的各个区间. 题目分析:简单的区间覆盖问题.可以按这样一种策略进行下去:在所有区间起点.长度有序的前提下,对于当前起点 ...
- ural 1303 Minimal Coverage【贪心】
链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 http://acm.hust.edu.cn/vjudge/contest/view ...
- UVa 10020 (最小区间覆盖) Minimal coverage
题意: 数轴上有n个闭区间[ai, bi],选择尽量少的区间覆盖一条指定线段[0, m] 算法: [start, end]为已经覆盖到的区间 这是一道贪心 把各个区间先按照左端点从小到大排序,更新st ...
随机推荐
- libvirt API管理hypervisors
发布一段C代码,用于连接指定的KVM宿主机器,获得该宿主机器的配置信息,以及该主机上所有的虚拟主机列表.状态及配置信息: #include <stdio.h>#include <st ...
- D - Mayor's posters - 2528(区间覆盖)
题意:贴海报 有一面很长的墙,大概有10000000 这么长,现有有一些海报会贴在墙上,当然贴海报的顺序是有先后的,问你当最后一张海报也贴上的时候能不能求出来在这面墙上能看到多少张不同的海报? 分析: ...
- Promise in AngularJS
What's promise Angular’s event system provides a lot of power to our Angular apps. One of the most p ...
- Linq to Sql语法及实例大全
LINQ to SQL语句(1)之Where Where操作 适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的 ,而判断条件就是它后面所接的 ...
- [Typescript] Introduction to Generics in Typescript
If Typescript is the first language in which you've encountered generics, the concept can be quite d ...
- rk3288 ov8858 camera移植
平台:瑞芯的rk3288 SDK:4.4/5.0/5.1 作者:fulinux *****本文同意转载.只是请注明出处:http://blog.csdn.net/fulinus**** rk3288的 ...
- IOS后台执行机制 与 动作
当用户按下"Home"键或者系统启动另外一个应用时,前台foreground应用首先切换到Inactive状态,然后切换到Background状态.此转换将会导致先后调用应用代理的 ...
- 纯CSS3实现超立体的3D图片侧翻倾斜效果
看到网友分享的一款CSS3 3D图片侧翻倾斜特效,觉得效果非常棒,其实话说回来,这玩意儿的实现真的非常简单,主要是创意不错.先来看看效果图.那么接下来我们分析一下源码吧,显示html代码,非常简单: ...
- 无限循环的ViewPager
目前情况 在不修改源码的情况下,当ViewPager滑动到最后一个item的时候,他就无法再往右滑动:当ViewPager滑动到第一个item的时候,他也无法再往前滑动.(以上全是废话) 设想 我们可 ...
- Citrix Presentation server can not contact the license server
If you come across the above error, you may also come across one or more of the errors below within ...