题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进。最后给出q个数,表示要输出第ni个进来的人的名字。

析:其实这就是一个模拟题,很容易知道是优先队列模拟,不能set,会超时,反正我是超时了,然后就一步步的模拟就好了,注意它给的时间可能不是按顺序,要排序,在比赛时我就没排序,一直WA。。。。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 150000 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct node{
int id, val;
char name[205];
bool operator < (const node &p) const{
return val < p.val || (val == p.val && id > p.id);
}
};
node a[maxn];
P pt[maxn];
int id[maxn];
int ans[maxn];
priority_queue<node> pq; int main(){
// ios::sync_with_stdio(false);
int T, q; cin >> T;
while(T--){
scanf("%d %d %d", &n, &m, &q);
for(int i = 0; i < n; ++i){
scanf("%s %d", a[i].name, &a[i].val);
a[i].id = i;
}
for(int i = 0; i < m; ++i)
scanf("%d %d", &pt[i].first, &pt[i].second);
sort(pt, pt+m);
pt[m].first = pt[m].second = 0;
for(int i = 0; i < q; ++i) scanf("%d", &id[i]);
int cnt = 0;
for(int i = 0, j = 0; i < n; ++i){
pq.push(a[i]);
if(i + 1 == pt[j].first){
int x = 0;
while(!pq.empty() && x < pt[j].second){
ans[cnt++] = pq.top().id;
pq.pop();
++x;
}
++j;
}
} while(!pq.empty()){
ans[cnt++] = pq.top().id;
pq.pop();
} for(int i = 0; i < q; ++i){
if(i) putchar(' ');
printf("%s", a[ans[id[i]-1]].name);
}
printf("\n");
} return 0;
}

最新文章

  1. 第二天--html+css
  2. 提高Visual Studio开发性能的几款插件
  3. ajax实现文件上传
  4. SpringMVC处理静态资源
  5. maven中Rhino classes (js.jar) not found - Javascript disabled的处理
  6. phpcms v9 中get的mysql查询表某字段最大值数据,表某字段不重复数据
  7. ExtJs之Ext.form.field.ComboBox组合框
  8. hadoop学习记录(一)HDFS
  9. [转] 小tip: 使用CSS将图片转换成黑白(灰色、置灰) ---张鑫旭
  10. myeclipse 于 否update software 解
  11. [转] PostgreSQL学习手册(函数和操作符)
  12. REVERSE关键字之REVERSE索引
  13. NOI十连测 第四测 T1
  14. Vue(小案例_vue+axios仿手机app)_购物车(二模拟淘宝购物车页面,点击加减做出相应变化)
  15. css table之合并单元格
  16. python -- 小数据池 is和 == 再谈编码
  17. ES6语法 promise用法
  18. java 面试算法题
  19. druid连接数据库加解密
  20. java 生成验证Guid码

热门文章

  1. Odoo 的库存管理与OpenERP之前的版本有了很大的不同,解读Odoo新的WMS模块中的新特性
  2. ab做压力测试
  3. POJ 1861 Network (MST)
  4. Android Studio 学习 - 程序安装
  5. MySQL内存表-临时表
  6. 虚拟机安装centos 6 报错Erro processing drive
  7. 你能识别这些科技公司的真假logo吗?
  8. MySQL与Oracle 差异比较之三函数
  9. linux 修改时间 - [命令操作]
  10. 理解javascript的caller,callee,call,apply概念