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个人进来,而且带的礼物价值越高就越先进入. ...
随机推荐
- day56_9_20orm中的关键字段,orm查询13方法整合,查询优化和事务。
一.常用字段. 在orm中有一些字段是常用字段: 1.AutoField 这个字段是自增的,必须填入参数primary_key=True,也就是说这个字段是表的主键,如果表类中没有自增列,就会自动创建 ...
- logback基本使用
logback基本使用 参考 Java日志框架:logback详解 # logback官网 http://logback.qos.ch/manual/index.html 使用步骤 构建logback ...
- SpringMVC的Java API(五)
1. HttpMessageConverter消息转换器 (1) HttpMessageConverter接口源码: public interface HttpMessageConverter< ...
- Python爬虫:
python中selenium操作下拉滚动条方法汇总 UI自动化中经常会遇到元素识别不到,找不到的问题,原因有很多,比如不在iframe里,xpath或id写错了等等:但有一种是在当前显示的页面元 ...
- CF1146D Frog Jumping
CF1146D Frog Jumping 洛谷评测传送门 题目描述 A frog is initially at position 00 on the number line. The frog ha ...
- VMWare虚拟机提示:另一个程序已锁定文件的一部分,打不开磁盘...模块"Disk"启动失败的解决办法
重启了电脑之后,打开VMware就发现出现了“锁定文件失败,打不开磁盘......模块"Disk"启动失败.”这些文字 为什么会出现这种问题: 这是因为虚拟机在运行的时候,会锁定文 ...
- Unity 2018 Cookbook (Matt Smith 著)
1. Displaying Data with Core UI Elements (已看) 2. Responding to User Events for Interactive UIs (已看) ...
- 分布式共识算法 (四) BTF算法(区块链使用)
系列目录 分布式共识算法 (一) 背景 分布式共识算法 (二) Paxos算法 分布式共识算法 (三) Raft算法 分布式共识算法 (四) BTF算法 一.引子 前面介绍的算法,无论是 Paxos ...
- ubuntu 16.04 上编译和安装C++机器学习工具包mlpack并编写mlpack-config.cmake | tutorial to compile and install mplack on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/1cd6a04d/,欢迎阅读最新内容! tutorial to compile and install mplack on ubun ...
- Vue.js 源码分析(二十三) 指令篇 v-show指令详解
v-show的作用是将表达式值转换为布尔值,根据该布尔值的真假来显示/隐藏切换元素,它是通过切换元素的display这个css属性值来实现的,例如: <!DOCTYPE html> < ...