zoukankan      html  css  js  c++  java
  • hdu 5437 Alisha’s Party 模拟 优先队列

    Problem Description
    Princess Alisha invites her friends to come to her birthday party. Each of her friends will bring a gift of some value v, and all of them will come at a different time. Because the lobby is not large enough, Alisha can only let a few people in at a time. She decides to let the person whose gift has the highest value enter first.

    Each time when Alisha opens the door, she can decide to let p people enter her castle. If there are less than p people in the lobby, then all of them would enter. And after all of her friends has arrived, Alisha will open the door again and this time every friend who has not entered yet would enter.

    If there are two friends who bring gifts of the same value, then the one who comes first should enter first. Given a query n Please tell Alisha who the nth person to enter her castle is.
     
    Input
    The first line of the input gives the number of test cases, T , where 1T15.

    In each test case, the first line contains three numbers k,m and q separated by blanks. k is the number of her friends invited where 1k150,000. The door would open m times before all Alisha’s friends arrive where 0mk. Alisha will have q queries where 1q100.

    The ith of the following k lines gives a string Bi, which consists of no more than 200 English characters, and an integer vi1vi108, separated by a blank.Bi is the name of the ith person coming to Alisha’s party and Bi brings a gift of value vi.

    Each of the following m lines contains two integers t(1tk) and p(0pk) separated by a blank. The door will open right after the tth person arrives, and Alisha will let p friends enter her castle.

    The last line of each test case will contain q numbers n1,...,nq separated by a space, which means Alisha wants to know who are the n1th,...,nqth friends to enter her castle.

    Note: there will be at most two test cases containing n>10000.
     
    Output
    For each test case, output the corresponding name of Alisha’s query, separated by a space.
     
    Sample Input
    1
    5 2 3
    Sorey 3
    Rose 3
    Maltran 3
    Lailah 5
    Mikleo 6
    1 1
    4 2
    1 2 3
     
    Sample Output
    Sorey Lailah Rose
     
    Source
     
     
     
     
    本来是一道简单的模拟题,我却花了很久的时间,一直wa,要跪了
    后来还是请教了别人才知道错在哪里了
    数据的时间是没有说是有序的,也就是时间的数据不一定是按照顺序给我们的。
    所以要先对数据进行排序。
     
    以后要时刻记住,输入数据一定要考虑乱序的情况。
     
     
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<queue>
     4 #include<algorithm>
     5 
     6 #define pb push_back
     7 
     8 using namespace std;
     9 
    10 const int maxn=150000+5;
    11 
    12 struct Node
    13 {
    14     int v,id;
    15     bool operator <(const Node&x)const
    16     {
    17         if(x.v==v)
    18             return x.id<id;
    19         return v<x.v;
    20     }
    21 };
    22 struct Time
    23 {
    24     int tim,num;
    25 };
    26 Time time[maxn];
    27 char name[maxn][205];
    28 Node ord[maxn];
    29 int ans[maxn];
    30 
    31 bool cmp(Time x,Time y)
    32 {
    33     return x.tim<y.tim;
    34 }
    35 
    36 priority_queue<Node>que;
    37 
    38 int main()
    39 {
    40     int test;
    41     scanf("%d",&test);
    42     while(test--){
    43         int n,m,q;
    44         scanf("%d %d %d",&n,&m,&q);
    45         for(int i=0;i<n;i++){
    46             scanf("%s %d",&name[i],&ord[i].v);
    47             ord[i].id=i;
    48         }
    49 
    50         for(int i=0;i<m;i++){
    51             scanf("%d %d",&time[i].tim,&time[i].num);
    52         }
    53 
    54         sort(time,time+m,cmp);
    55 
    56         while(!que.empty())
    57             que.pop();
    58 
    59         int now=0,len=0;
    60         for(int j=0;j<m;j++){
    61             while(now<time[j].tim){
    62                 que.push(ord[now]);
    63                 now++;
    64             }
    65             while(time[j].num--){
    66                 ans[len++]=que.top().id;
    67                 que.pop();
    68                 if(que.empty())
    69                     break;
    70             }
    71         }
    72         while(now<n){
    73             que.push(ord[now++]);
    74         }
    75         while(!que.empty()){
    76             ans[len++]=que.top().id;
    77             que.pop();
    78         }
    79         int c;
    80         for(int i=0;i<q-1;i++){
    81             scanf("%d",&c);
    82             printf("%s ",name[ans[c-1]]);
    83         }
    84         scanf("%d",&c);
    85         printf("%s
    ",name[ans[c-1]]);
    86     }
    87     return 0;
    88 }
    View Code
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    JAVA合并两个有序的单链表,合并之后的链表依然有序
    excel如何将一个单元格内容拆分成多个单元格?(用到了数据->分列)
    Navicat导入excel的xlsx文件提示无法打开文件
    Request对象实现请求转发
    MessageFormat.format()和String.format()
    使用Servlet动态生成验证码
    Http协议
    使用freemarker导出word
    java注解学习(1)注解的作用和三个常用java内置注解
    SSM_CRUD新手练习(6)分页后台控制器编写
  • 原文地址:https://www.cnblogs.com/-maybe/p/4805493.html
Copyright © 2011-2022 走看看