您的位置:首页 > 其它

hdu5437Alisha’s Party

2015-09-15 11:12 190 查看
简单地优先队列模拟

[code]#include<bits/stdc++.h>
using namespace std;

char s[150001][210];
int value[150001];
char ans[150001][210];
int mx;
int ans1[101];
int n,m,k;
struct Node{
    int time;
    int num;
}open[150001];

struct node{
    int index;
    char s[201];
    int value;
    friend bool operator <(node a,node b){
        if(a.value==b.value){
            return a.index>b.index;
        }
        return a.value<b.value;
    }
};

void solve(){
    priority_queue<node>Q;
    int cnt1=1;
    int cnt2=1; //来了几个人
    for(int i=1;i<=m;i++){
        while(cnt2<=open[i].time){
            node a;
            a.index=cnt2;
            a.value=value[cnt2];
            strcpy(a.s,s[cnt2]);
            Q.push(a);
            cnt2++;
        }
        int ans3=0;
        while(ans3<open[i].num&&!Q.empty()){
            node a=Q.top();
            strcpy(ans[cnt1++],a.s);
            if(cnt1>mx)
                break;
            Q.pop();
            ans3++;
        }
    }
    if(cnt1>mx)
        return ;
    for(int i=cnt2;i<=n;i++){
        node a;
        a.index=i;
        a.value=value[i];
        strcpy(a.s,s[i]);
        Q.push(a);
    }
    while(!Q.empty()){
        node a=Q.top();
        strcpy(ans[cnt1++],a.s);
        if(cnt1>mx)
            break;
        Q.pop();
    }
}

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

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1;i<=n;i++)
            scanf("%s%d",s[i],&value[i]);
        for(int i=1;i<=m;i++)
            scanf("%d%d",&open[i].time,&open[i].num);
        sort(open+1,open+m+1,cmp);
        mx=0;
        for(int i=1;i<=k;i++){
            scanf("%d",&ans1[i]);
            if(ans1[i]>mx){
                mx=ans1[i];
            }
        }
        solve();
        int x;
        for(int i=1;i<=k;i++){
            if(i==1)
                printf("%s",ans[ans1[i]]);
            else
                printf(" %s",ans[ans1[i]]);
        }
        printf("\n");
    }
    return 0;
}
/*
100
5 2 3
Sorey 3
Rose 3
Maltran 3
Lailah 5
Mikleo 6
1 1 4 2
1 2 3
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: