hdu 3288 Resource Allocation
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=3288
Resource Allocation
Description
HDU-Sailormoon is made up of three girls~~~wj, xq, lff, usually they work together ---- solve a variety of problems. So they has to use some resources in the process.
In order to make it more convenient, they will put some resources in a box big enough, each resource has its ID and level of priority. When they want a kind of resources, they will give its ID and get it from the box. If there are several ones available in the box, they will get the highest priority ones. If there are still several ones available, they will get the one which puts in the box first.
Input
The input will consist of several cases, please deal with till the end of file. Each case contains a integer N(0<N<=10000), representing there are N steps following. For example, if input is "R x y"(x, y are integers,0<=x,y<=10000), representing they put a resource to the box, its ID is x, and its priority is y(the higher the priority is, the smaller the y is). If input is "name r" (name may be "wj" or "xq" or "lff", r is an integer,0<=r<=10000), representing one girl called "name" wants a resource, which ID is r.
Output
When the input is "R x y", the resource will mark a number k (begin from 1). When the input is "name r", please find out a resource in the box, if there is one available, print "name gets Num k: x y!", name referred to the input, k is the mark number of resource, x is the resource's ID and y is the level of priority, or print "No one fits!".
Sample Input
9
R 1 5
R 2 3
R 1 5
R 2 0
wj 1
xq 2
lff 3
lff 2
xq 2
Sample Output
wj gets Num 1: 1 5!
xq gets Num 4: 2 0!
No one fits!
lff gets Num 2: 2 3!
No one fits!
优先队列。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::set;
using std::pair;
using std::vector;
using std::multiset;
using std::priority_queue;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef unsigned long long ull;
struct Node {
int fix, pos;
Node(int i = , int j = ) :fix(i), pos(j) {}
inline friend bool operator<(const Node &a, const Node &b) {
return a.fix == b.fix ? a.pos > b.pos : a.fix > b.fix;
}
};
priority_queue<Node> que[N];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
char buf[];
int n, id, fix;
while (~scanf("%d", &n)) {
int pos = ;
rep(i, n) {
scanf("%s", buf);
if (buf[] == 'R') {
scanf("%d %d", &id, &fix);
que[id].push(Node(fix, pos++));
} else {
scanf("%d", &id);
if (que[id].empty()) { puts("No one fits!"); continue; }
Node t = que[id].top(); que[id].pop();
printf("%s gets Num %d: %d %d!\n", buf, t.pos, id, t.fix);
}
}
rep(i, N) while (!que[i].empty()) que[i].pop();
}
return ;
}
hdu 3288 Resource Allocation的更多相关文章
- Spark动态资源分配-Dynamic Resource Allocation
微信搜索lxw1234bigdata | 邀请体验:数阅–数据管理.OLAP分析与可视化平台 | 赞助作者:赞助作者 Spark动态资源分配-Dynamic Resource Allocation S ...
- Hadoop Aggregate Resource Allocation解释
1.在hadoop里面运行程序的时候,查看某个任务的具体信息如下: [hadoop@master monitor]$ yarn application -list 如上图,这里面的Aggregate ...
- HDU - 3247 Resource Archiver (AC自动机,状压dp)
\(\quad\)Great! Your new software is almost finished! The only thing left to do is archiving all you ...
- Resource Allocation of Yarn
关键词:yarn 资源分配 mapreduce spark 简要指南 适合不想看太多原理细节直接上手用的人. 基本原则: container分配的内存不等于机器实际用掉的内存.NM给container ...
- HDU 3247 Resource Archiver (AC自己主动机 + BFS + 状态压缩DP)
题目链接:Resource Archiver 解析:n个正常的串.m个病毒串,问包括全部正常串(可重叠)且不包括不论什么病毒串的字符串的最小长度为多少. AC自己主动机 + bfs + 状态压缩DP ...
- HDU 3247 Resource Archiver (AC自动机+BFS+状压DP)
题意:给定 n 个文本串,m个病毒串,文本串重叠部分可以合并,但合并后不能含有病毒串,问所有文本串合并后最短多长. 析:先把所有的文本串和病毒都插入到AC自动机上,不过标记不一样,可以给病毒标记-1, ...
- Service Function Chaining Resource Allocation: A Survey
摘要: 服务功能链(SFC)是未来Internet的一项关键技术. 它旨在克服当前部署模型的僵化和静态限制. 该技术的应用依赖于可以将SFC最佳映射到衬底网络的算法. 这类算法称为"服务功能 ...
- HDU 3247 Resource Archiver(AC自动机 + 状压DP + bfs预处理)题解
题意:目标串n( <= 10)个,病毒串m( < 1000)个,问包含所有目标串无病毒串的最小长度 思路:貌似是个简单的状压DP + AC自动机,但是发现dp[1 << n][ ...
- Solving Large-Scale Granular Resource Allocation Problems Efficiently with POP(2021-POP-SOSP-文献阅读笔记)
读者 这篇文章来自2021的SOSP,单位是斯坦福大学和微软.选该文章的理由有二,一是资源分配的主题较为相关:二是文章结构.语言很清晰,读起来很舒服. 本文的中心思想可以概括为:分化瓦解,各个击破.即 ...
随机推荐
- PMP考试--价值工程法
如果你对项目管理.系统架构有兴趣,请加微信订阅号"softjg",加入这个PM.架构师的大家庭 ValueEngineering,简称VE,是降低成本提高经济效益的有效方法,价值工 ...
- Alfresco安装与配置图解
Alfresco安装与配置图解 Alfresco是一款开源的企业内容管理系统(ECM),为企业提供了日常的文档管理.工作流(可以和企业目前的OA协同接合使用).工作记录管理.知识管理.网络内容管理.图 ...
- LoadRunner用户行为模拟器 《第三篇》
用户行为模拟器简称VU,VU通过运行VU脚本模拟了用户对软件的操作行为.VU是基于网络协议的.很明显,被测服务器是通过各种各样的网络协议与客户端打交道的.VU要“骗过”被测服务器,当然就要遵守这些协议 ...
- ios NSString常见的字符串操作 分割 查找
1.NSString *str = [[NSString alloc]init]; //简单粗暴,基本用不到 2.NSString *str = [[NSString alloc]initWi ...
- nice和taskset命令
taskset -c 9,10 bash domain_analysis.sh && /home/work/odp/php/bin/php hourly_localdns_hijack ...
- Use EnCase to acquire data from a smartphone
Yesterday someone asked me a question can EnCase acquire data from a smartphone, and my reply was &q ...
- hdu2099
注意是两位数,必须输出01,02,03,这种 #include <stdio.h> int main(){ int begin,end; int i; ]; int cnt; int si ...
- 写给Node.js新手的7个小技巧
一些我更愿意在开始就知道东西 利用 Node.js 开发是一个非常有趣,和令人满足的过程, 他有3万多个模块可以选择使用,并且所有的模块可以非常容易的集成入现有的应用之中. 无论如何,对于一些刚开始使 ...
- Solaris网络配置
/etc/hostname.interface:物理端口,里面包含一个主机名或主机的IP/etc/nodename:计算机名/etc/defaultdomain:主机域名/etc/defaultrou ...
- STL使用sort注意的问题
结构体使用sort算法时,重载operator<(..).如果我们按下面这样写 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...