csp 201709-2 优先队列模拟
数据规模:
用优先队列对各个事件的发生先后记录即可:
#include<iostream>
#include<queue> using namespace std;
int key[];
struct node
{
int no;
int begin;
int end;
int type;//表示借,1表示时在还
node(int no, int begin,int end, int type):no(no),begin(begin),end(end),type(type)
{ }
friend bool operator <(node a, node b)
{
if(!a.type)
{
if(!b.type)//都是借
{
return a.begin>b.begin;
}
else//借遇到还的
{
return (a.begin>=(b.begin+b.end));
}
}
else
{
if (!b.type)
{
return (a.begin+a.end)>b.begin;
}
else
{
//都是还
if((a.begin+a.end)>(b.begin+b.end))
return true;
else if((a.begin+a.end)==(b.begin+b.end))
return a.no > b.no;
else
return false;
}
}
};
};
priority_queue<node> q; int main()
{
ios::sync_with_stdio(false);
int N,k;
cin>>N>>k;
node t(,,,);
int a,b,c;
for(int i=;i<N;i++)
{
key[i]=i+;
}
while(k--)
{
cin>>a>>b>>c;
q.push(node(a,b,c,));
q.push(node(a,b,c,));
}
while(!q.empty())
{
t=q.top();
//cout<<t.no<<t.type<<endl;
if(!t.type)
{
for (int i = ; i < N; i++)
{
if(key[i]==t.no)
{
key[i]=-;
break;
}
}
}
else
{
for (int i = ; i < N; i++)
{
if(key[i]==-)
{
key[i]=t.no;
break;
}
}
}
q.pop();
}
for (int i = ; i < N; i++)
{
cout<<key[i]<<" ";
}
return ;
}
csp 201709-2 优先队列模拟的更多相关文章
- HDU 5437 Alisha’s Party (优先队列模拟)
题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...
- Alisha’s Party (HDU5437)优先队列+模拟
Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来.用优先队列模拟即可.需要定义朋友结构体,存储每个人的到达顺序以及 ...
- hdu 5437(优先队列模拟)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)
优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...
- 暑假练习赛 004 E Joint Stacks(优先队列模拟)
Joint StacksCrawling in process... Crawling failed Time Limit:4000MS Memory Limit:65536KB 64 ...
- Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心
http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...
- Problem E: 穷游中国在统题 优先队列 + 模拟
http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=4 Problem E: 穷游中国在统题 Description Travel ...
- bzoj1216 操作系统(优先队列模拟)
1216: [HNOI2003]操作系统 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1172 Solved: 649[Submit][Statu ...
- 优先队列 + 模拟 - HDU 5437 Alisha’s Party
Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...
随机推荐
- 2019.6.13_MySQL简单命令的使用
1.show databases; -- 显示当前连接下的数据库 2.use db_name; -- 使用当前数据库db_name 3.show tables; -- 显示当前数据库下数 ...
- [C7] 支持向量机(Support Vector Machines) (待整理)
支持向量机(Support Vector Machines) 优化目标(Optimization Objective) 到目前为止,你已经见过一系列不同的学习算法.在监督学习中,许多学习算法的性能都非 ...
- 2019年最新50道java基础部分面试题
[软帝学院]1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语法,集合的语法,io 的语法,虚拟机方面的语法. 1.一个".j ...
- 【香甜的黄油 Sweet Butter】
[香甜的黄油 Sweet Butter] 洛谷P1828 https://www.luogu.org/problemnew/show/P1828 JDOJ 1803 https://neooj.com ...
- windows xp 安装后不能能ping,浏览器不能上网
windows xp MSDN版本 下载地址: ed2k://|file|zh-hans_windows_xp_home_with_service_pack_3_x86_cd_x14-92408.is ...
- COMP 2406 – F19
COMP 2406 – F19 – A4 Due Friday, November 22nd at 11:59 PMAssignment 4 Trivia Quiz BuilderSubmit a s ...
- js生成条形码
生成条形码 <body> <div> <img id="ma"/> </div> </body> </html&g ...
- 明解C语言 中级篇 第二章答案
练习2-1 /* 倒计时后显示程序运行时间 */ #include <time.h> #include <stdio.h> /*--- 等待x毫秒 ---*/ int slee ...
- Python之np.random.permutation()函数的使用
官网的解释是:Randomly permute a sequence, or return a permuted range. 即随机排列序列,或返回随机范围.我的理解就是返回一个乱序的序列.下面通过 ...
- 第二十一节:Asp.Net Core MVC和WebApi路由规则的总结和对比
一. Core Mvc 1.传统路由 Core MVC中,默认会在 Startup类→Configure方法→UseMvc方法中,会有默认路由:routes.MapRoute("defaul ...