cf754D
题意:给你一个数m,有多少优惠券,给个n,主角想用多少优惠券。然后接下来时m行,每行两个数,那张优惠券的优惠区间a,b(在a号货物到b号货物之间的所有都可以优惠)
问你,能不能用k张优惠券,是他的优惠区间重叠的部分最大。
今天第一次看优先队列,居然还有这么神奇的东西,omg,太强了
思路就是排序,然后用优先队列乱搞一下。。。
接下来给出代码
#include <iostream>
#include <queue>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int Maxn = 2147483647;
struct Node{
int l,r;
int i;
}node[300010];
bool cmp( const Node &a,const Node &b ){
return ( a.l == b.l ? a.r < b.r:a.l < b.l );
}
int main(){
int m,n;
scanf("%d%d",&m,&n);
for( int i = 1; i <= m; i++ ){
scanf("%d%d",&node[i].l,&node[i].r);
node[i].i = i;
}
sort( node+1,node+1+m,cmp );
priority_queue<int,vector<int>,greater<int> > q;
int inf = -Maxn;
int x;
int l,r;
for( int i = 1; i <= m; i++ ){
x = node[i].l;
q.push( node[i].r );
while( q.top() < x || q.size() > n ){
q.pop();
}
if( q.size() == n ){
if( inf < q.top() - x + 1 ){
inf = q.top() - x + 1;
l = x,r = q.top();
}
}
}
if( inf == - Maxn ){
cout << '0' << endl;
for( int i = 1; i <= n; i++ ){
printf( "%d ",i );
}
printf( "\n" );
exit(0);
}else{
cout << inf << endl;
for( int i = 1; i <= m; i++ ){
if( node[i].l <= l && node[i].r >= r ){
printf("%d ",node[i].i);
n--;
if( n == 0 ){
cout << '\n';
exit(0);
}
}
}
}
}
cf754D的更多相关文章
随机推荐
- c#中创建类(更新中)
类是最常见的一种引用类型,最简单的定义如下 class YouClassNam {} 复杂的类可能包含一下内容 类属性 类属性以及类修饰符. 非嵌套的类修饰符有:public,internal,ab ...
- 常见排序算法(PHP实现)
function InsertSort($arr){ $num = count($arr); for($i = 1; $i < $num; $i++){ $key = $arr[$i]; for ...
- 旧版Xcode下载地址
怕忘记了,做个记号 https://developer.apple.com/downloads/
- Centos开启FTP及用户配置
vsftpd作为FTP服务器,在Linux系统中是非常常用的.下面我们介绍如何在centos系统上安装vsftp. 什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...
- cocos2d-x Tests讲解 Particle System(粒子系统)
转载请注明出处: http://www.cnblogs.com/shangdahao/archive/2012/04/14/2447571.html 一.粒子系统简介: 粒子系统最早出现在80年代,主 ...
- handoff了解
iOS8推出一个新特性,叫做Handoff.Handoff中文含义为换手(把接力棒传给下一个人),可以在一台Mac和iOS设备上开始工作,中途将工作交换到另一个Mac或iOS设备中进行.这个在iOS8 ...
- AirPlay简介
AirPlay是苹果公司在iOS4.2即Mac OS Mountain Lion中加入的一种播放技术.可以将iPhone.iPod.iPad和Mac上的视频镜像传送到支持AirPlay的设备上(如音响 ...
- 《Linux命令行大全》系列(一、shell是什么)
学习 Linux, 从命令开始 图形界面只是让简单事情,更简单 图形化界面能快速处理简单的事情,如打开/关闭文件 然后,随着事务复杂度的提升,图形化界面的操作也就繁琐起来 例如,word中插入一个图片 ...
- 根据WSDL生成代理类方式(2)
运行开发人员工具提示 输入命令行svcutil http://localhost:8080/Test/TestClassPort?wsdl
- python,django,mysql版本号查询
1. ubuntu 下如何查询子集的mysql版本: 方法一: 登录子集的mysql之后就会显示mysql版本: ***:~$ mysql -u root -p Enter password: Wel ...