您的位置:首页 > 其它

HDU 5437 模拟

2015-09-17 08:20 211 查看
HDU 5437

题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5437
题意:

一些人,身上带有权值。

他们会按照标号来到门口。

现在有一些开门时间,以第几个人来时为点。每次只能放少于等于pi人进来。先放权值大的,权值相等放编号小的。

对于给定的数值mark,输出第mark个进来的人是谁。

思路:

简单题,任意优雅姿势。在少于等于Pi处WA了几发,没看清少于 的这种情况

采用优先队列,每次弹出记录一下。

题目表述有问题,每个人进来的顺序需要按他们的编号排序。

源码:

#include <cstdio>

#include <cstring>

#include <cmath>

#include <cstdlib>

#include <algorithm>

#include <iostream>

#include <set>

#include <queue>

#include <utility>

using namespace std;

typedef pair<int,int> pii;

struct D

{

char str[205];

int val;

int mark;

bool operator < (const D &rbs)const

{

if(val != rbs.val)

return val < rbs.val;

return mark > rbs.mark;

}

}d[150005];

struct Node

{

int u, v;

}node[150005];

bool cmp(Node a, Node b){return a.u < b.u;}

priority_queue<D>que;

char ans[150005][205];

int main()

{

// freopen("1001.in", "r", stdin);

int t;

scanf("%d", &t);

while(t--){

int n, m, q;

scanf("%d%d%d", &n, &m, &q);

for(int i = 0 ; i < n ; i++){

scanf("%s %d", d[i].str, &d[i].val);

d[i].mark = i;

}

while(!que.empty()) que.pop();

int now1 = 0, now2 = 0;;

for(int i = 0 ; i < m ; i++)

scanf("%d%d", &node[i].u, &node[i].v);

sort(node, node + m, cmp);

for(int i = 0 ; i < q ; i++){

while(now1 < node[i].u){

que.push(d[now1++]);

}

while(now2 < now1 && !que.empty() && node[i].v--){

D temp = que.top(); que.pop();

strcpy(ans[now2++], temp.str);

// memcpy(ans[now2++], temp.str, sizeof(temp.str));

}

}

while(now1 < n){

que.push(d[now1++]);

}

while(!que.empty()){

D temp = que.top(); que.pop();

strcpy(ans[now2++], temp.str);

// memcpy(ans[now2++], temp.str, sizeof(temp.str));

}

// for(int i = 0 ; i < n ; i++)

// printf("ans[%d] = %s\n", i, ans[i]);

int f = 1;

while(q--){

int temp;

scanf("%d", &temp);

if(f) f = 0;

else printf(" ");

printf("%s", ans[temp - 1]);

}

printf("\n");

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: