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,单位是斯坦福大学和微软.选该文章的理由有二,一是资源分配的主题较为相关:二是文章结构.语言很清晰,读起来很舒服. 本文的中心思想可以概括为:分化瓦解,各个击破.即 ...
随机推荐
- 支撑5亿用户、1.5亿活跃用户的Twitter最新架构详解及相关实现
如果你对项目管理.系统架构有兴趣,请加微信订阅号"softjg",加入这个PM.架构师的大家庭 摘要:Twitter出道之初只是个奋斗在RoR上的小站点,而如今已拥有1.5亿的活跃 ...
- MySQL数据库获取多个汉字拼音的首字母函数
需求简介:最近的一个项目,想实现如下图所示的显示效果.很明显,如果能够获取对应的汉字词组中每个汉字的拼音首字母就可以实现了,如果是固定的几组汉字,人为的拼一下就可以 了,不过项目中有多处功能需要这个效 ...
- django中添加用户
在django中添加用户,直接在auth_user表中添加会有问题,因为这里密码是加密的,可以通过manage.py shell加入 创建User: 1 >>> from djang ...
- USACO Section 2.2 循环数 Runaround Numbers
OJ:http://www.luogu.org/problem/show?pid=1467 #include<iostream> #include<vector> #inclu ...
- ASPxGridView中批量提交及个别提交的写法
//获取chech box ID protected string GetProtoID() { string protoId = ""; //获取选中的记录Id List< ...
- 简化对象extend拓展
发现对对象继承或拷贝的时候,总是要$点来点去好麻烦,我的解决办法如下: (function(){ Object.prototype.extend = function(o){ $.extend(tru ...
- CLRS:build_max_heap(strorage in array)
//用满二叉树存储,从n/2处开始递归向上调整(n/2后均为叶子节点,无需调整)使得根最大 //满二叉树顺序存储,左子2i,右子2i+1: #include<stdio.h>#includ ...
- iface eth0 inet dhcp
- svn 检出代码报ssl错误问题的解决
svn: OPTIONS of 'https://192.168.11.185/svn/ahwater-cloud': SSL handshake failed: SSL error: Key usa ...
- WP8_访问ListBox中的Item项中的某个元素
How to access a Control placed inside ListBox ItemTemplate in WP7(转) In this post I am going to talk ...