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!

优先队列。。

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<queue>
 8 #include<set>
 9 using std::cin;
10 using std::cout;
11 using std::endl;
12 using std::find;
13 using std::sort;
14 using std::set;
15 using std::pair;
16 using std::vector;
17 using std::multiset;
18 using std::priority_queue;
19 #define pb(e) push_back(e)
20 #define sz(c) (int)(c).size()
21 #define mp(a, b) make_pair(a, b)
22 #define all(c) (c).begin(), (c).end()
23 #define iter(c) decltype((c).begin())
24 #define cls(arr,val) memset(arr,val,sizeof(arr))
25 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
26 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
27 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
28 const int N = 10010;
29 typedef unsigned long long ull;
30 struct Node {
31     int fix, pos;
32     Node(int i = 0, int j = 0) :fix(i), pos(j) {}
33     inline friend bool operator<(const Node &a, const Node &b) {
34         return a.fix == b.fix ? a.pos > b.pos : a.fix > b.fix;
35     }
36 };
37 priority_queue<Node> que[N];
38 int main() {
39 #ifdef LOCAL
40     freopen("in.txt", "r", stdin);
41     freopen("out.txt", "w+", stdout);
42 #endif
43     char buf[10];
44     int n, id, fix;
45     while (~scanf("%d", &n)) {
46         int pos = 1;
47         rep(i, n) {
48             scanf("%s", buf);
49             if (buf[0] == ‘R‘) {
50                 scanf("%d %d", &id, &fix);
51                 que[id].push(Node(fix, pos++));
52             } else {
53                 scanf("%d", &id);
54                 if (que[id].empty()) { puts("No one fits!"); continue; }
55                 Node t = que[id].top(); que[id].pop();
56                 printf("%s gets Num %d: %d %d!\n", buf, t.pos, id, t.fix);
57             }
58         }
59         rep(i, N) while (!que[i].empty()) que[i].pop();
60      }
61     return 0;
62 }

时间: 2024-10-12 13:06:38

hdu 3288 Resource Allocation的相关文章

hdu 3247 Resource Archiver(AC自动机+BFS+DP)

题目链接:hdu 3247 Resource Archiver 题目大意:给定N个需要包含的串,M个不能包含的串,问说满足的最短字符串长度. 解题思路:直接对所有串建立AC自动机,不能满足的串用同一种标记即可.然后处理出所有属于需要包含串的单词节 点,用BFS处理出两两之间的距离,并且过程中是不能经过禁止节点.这样做的原因是节点的个数很多,如果对所有的 节点进行dp的话空间都不够.剩下的就是dp了. #include <cstdio> #include <cstring> #inc

LTE下行物理层传输机制(6)-下行资源分配方式(Resource Allocation Type)

下行RB的资源分配(Resource Allocation)有三种方式,分别是资源分配方式0.资源分配方式1和资源分配方式2.在上一篇博文<LTE下行物理层传输机制(5)-DCI格式的选择和DCI1A>中提到DCI1A的时候,提到DCI1A只能分配连续的RB,以及这种方式下RIV(Resource Indication Value )的计算,那么这种分配方式其实就是资源分配方式2.而DCI2和DCI2A格式使用的则是另外2种不同的分配方式,即资源分配方式0和资源分配方式1.因此在讲DCI2和D

Mesos Resource Allocation Algo: DRF(Dominant Resource Fairness)

http://datastrophic.io/resource-allocation-in-mesos-dominant-resource-fairness-explained/ Original paper at: https://people.eecs.berkeley.edu/~alig/papers/drf.pdf Key Take-away: Dominant resource - a resource of specific type (cpu, memory, disk, port

HDU 3247 Resource Archiver (AC自己主动机 + BFS + 状态压缩DP)

题目链接:Resource Archiver 解析:n个正常的串.m个病毒串,问包括全部正常串(可重叠)且不包括不论什么病毒串的字符串的最小长度为多少. AC自己主动机 + bfs + 状态压缩DP 用最短路预处理出状态的转移.能够优化非常多 AC代码: #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <queue> us

HDU 3247 Resource Archiver (AC自动机 + BFS + 状态压缩DP)

题目链接:Resource Archiver 解析:n个正常的串,m个病毒串,问包含所有正常串(可重叠)且不包含任何病毒串的字符串的最小长度为多少. AC自动机 + bfs + 状态压缩DP 用最短路预处理出状态的转移.可以优化很多 AC代码: #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <queue> using n

Resource Allocation of Yarn

关键词:yarn 资源分配 mapreduce spark 简要指南 适合不想看太多原理细节直接上手用的人. 基本原则: container分配的内存不等于机器实际用掉的内存.NM给container分配的内存是预留这么多内存,但实际用多少取决于你的-Xmx加上你的堆外内存.大部分堆外内存使用不多的情况下,实际主要就是JVM堆内存. container内存是按yarn.scheduler.minimum-allocation-mb的整数倍分配的,用户设置的内存不足整数倍会向上取整,并且不会超过 

HDU 3247 Resource Archiver AC自动机 + bfs + 状态压缩dp

题意:给定你n个文本串 ,m个模式串,怎么构造最短的新的文本串使得这个新的文本串包含n个文本串的所有信息且文本串的长度最短且不包含模式串. 解题思路:这里看题解撸的,首先我们算出两两文本串的距离(end数组标记文本和模式串的值不同,利用这个进行bfs算出两两之间的最短距离,注意到这里模式串的end是不能走到的.这里也不需要松弛操作),然后因为n只有10这么大,所以我们可以状态压缩  ,dp[i][j] 表示 压缩后状态为 i(二进制压缩,每i位表示第i个是否在)且 以j结尾的文本串的最小花费.这

[AC自动机+spfa+状压dp] hdu 3247 Resource Archiver

题意: 给n个本源串,m个病毒串 求一个最多的长度的单词包含所有的本源串并不包含任意一个病毒串 串均为01串 思路: 只有10个本源串 一开始想的是直接建立完trie图 然后在图上直接spfa 结果发现 dis[60005][1030] 超内存了 这个时候就要想到 其实只有节点的mark值大于0的节点是我们需要用的 就是那些含有状压权值的节点 那么我们先记录下这些节点是哪些 然后发现其实这些不到100个节点 所以跑100遍spfa 求出两两之间的最短路 然后用这个距离 去状压dp 数组就成了 d

PatentTips - Systems, methods, and devices for dynamic resource monitoring and allocation in a cluster system

BACKGROUND? 1. Field? The embodiments of the disclosure generally relate to computer clusters, and more particularly to systems, methods, and devices for the efficient management of resources of computer clusters.? 2. Description of the Related Art?