hdu5437 Alisha’s Party 优先队列
来源:互联网 发布:四维星设计软件 编辑:程序博客网 时间:2024/06/15 05:22
2015年长春网络赛1001
题意:有k个人要来,其中要开m次门,每次开门之前前t个人到了,可以进去p个人,最后q次询问第几个进去的人的编号
分析:这题网络赛时想到用优先队列做了,结果一直WA感觉好没道理下去后发现要对(t,p)排序,还是太弱了啊,而且下去自己敲得代码还一直有错,原来有警告都没发现,结果又是一直WA啊。。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <set>#include <vector>using namespace std;const int maxn = 150000 + 5;struct node{ char name[201]; int id; int val;};node s[maxn];int ans[maxn];struct st{ int t, p; bool operator < (const st &a) const { return t < a.t; }}in[maxn];struct cmp{ bool operator()(const int& i,const int&j)const//优先队列和sort里的运算符重载刚好相反,长记性了 { return s[i].val < s[j].val || (s[i].val == s[j].val && s[i].id > s[j].id); }};priority_queue<int,vector<int>,cmp> q;int main(){ //freopen("input.txt", "r", stdin); int t; scanf("%d",&t); while (t--) { int k, m, qus; memset(s, 0, sizeof(s)); memset(in, 0, sizeof(in)); scanf("%d%d%d", &k, &m, &qus); for (int i = 1; i <= k; i++) { scanf("%s%d", s[i].name, &s[i].val); s[i].id = i; } while (!q.empty())q.pop(); for (int i = 0; i < m; i++) { scanf("%d%d", &in[i].t, &in[i].p); } sort(in, in + m); int rear = 1; int cnt = 0; for (int i = 0; i < m; i++) { for (; rear <= in[i].t; rear++) { q.push(rear); } for (int j = 0; j < in[i].p; j++)//此处BUG让我调了好久,注意j { if (!q.empty()) { int pos=q.top(); ans[++cnt]=pos; q.pop(); } else break; } } for (; rear <= k; rear++) { q.push(rear); } while (!q.empty()) { int pos=q.top(); ans[++cnt]=pos; q.pop(); } int x; scanf("%d", &x); printf("%s", s[ans[x]].name); for (int i = 1; i < qus; i++) { scanf("%d", &x); printf(" %s", s[ans[x]].name); } printf("\n"); } return 0;}
0 0
- hdu5437 Alisha’s Party 优先队列
- [hdu5437] Alisha’s Party(优先队列)
- HDU5437 Alisha’s Party 优先队列
- hdu5437 Alisha’s Party(优先队列、模拟)
- HDU5437 - Alisha’s Party (优先队列 模拟)
- HDU5437 Alisha’s Party(优先队列+模拟)
- hdu5437 Alisha’s Party
- HDU5437(2015长春网赛)——Alisha’s Party(优先队列)
- 优先对列模拟 hdu5437 Alisha’s Party
- HDU 5437 Alisha’s Party 优先队列
- hdu 5437 Alisha’s Party 优先队列
- hud5437-Alisha’s Party-优先队列
- hdu 5437Alisha’s Party(优先队列)
- hdu 5437 Alisha’s Party (优先队列)
- hdu 5437 Alisha’s Party 优先队列
- HDU 5437 Alisha’s Party 优先队列
- hdu 5437 Alisha’s Party(优先队列)
- hdu 5437 Alisha’s Party(优先队列)
- CodeForces 576A - Vasya and Petya's Game
- FP_growth算法
- 大整数的乘法运算
- 详解java类的生命周期
- 基于深层神经网络的命名实体识别技术
- hdu5437 Alisha’s Party 优先队列
- lintcode做题总结, Sept 15
- 那些年我们追过的网络库(PartI)
- ugly number
- eclipse 上传项目到git
- Android UI学习(一)
- HashMap遍历 key value
- Idea 工具的一些使用
- 2015.9.15 自定义异常的完整练习