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的更多相关文章
随机推荐
- jquery右下角返回顶部
实现的效果也就是,当有滚动条是,滚动条未动或与顶部距离小于多少像素是,返回顶部按钮处于隐身状态,当滚动条与顶部距离大于一定像素时,返回顶部按钮出现,实现点击‘返回按钮’后,从当前位置回到等不位置.要先 ...
- PHPUnit初试
先测试了一下加减,检查一下环境,又调用函数测试了服务器名. 源代码: class DemoController extends \Think\Controller { /** * @assert (5 ...
- 黑马程序员-------.net基础知识一
一 初识.net .net是一种多语言的编程平台,可以用多达几十种的语言来进行开发,而C#就是基于.net平台的其中一种开发语言. 它的特点是: ⒈多平台:该系统可以在广泛的计算机上运行,包括从服务 ...
- Morgan stanley 电话面试
首先是聊项目, 不会涉及到具体的技术问题 1.C和C++的区别:C++里的RTTI 2.vector 和 list的区别 : casting operator ; smart pointer. 3.数 ...
- win7系统cocos2dx 3.4 绑定自定义类到Lua
Cocos2d-x 3.0开始使用bindings-generator来生成c++类的lua绑定.bindings-generator基于tolua++,通过配置tools/tolua中的ini文件以 ...
- the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header
the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header ...
- OA学习笔记-009-岗位管理的CRUD
一.分析 Action->Service->Dao CRUD有功能已经抽取到BaseDaoImpl中实现,所以RoleDaoImpl没有CRUD的代码,直接从BaseDaoImpl中继承 ...
- 《ruby编程语言》笔记 1
赋值: ruby支持并行赋值,即允许在赋值表达式中出现多余一个值和多于一个的变量: x,y=1,2a,b=b,ax,y,z=[1,2,3] (python同样可以正常上面的语句). Methods i ...
- android 世界各国英文简写代码 资源文件
今日又用到这段代码,忽然感觉到如果是第一次用的人肯定也会很麻烦.故在此上传一份.后人再用就不必重复做此工作.跟体育老师学过语文,见谅. 提供下载地址 http://download.csdn.net/ ...
- 子查询解嵌套not in 无法展开改写
SQL> explain plan for select * from OPS$CZTEST1.SAVJ_ATOMJOURBAK where ((list_flag = '1' and prt_ ...