• hdu 3288 Resource Allocation


    题意:纯模拟题,用N个优先队列表示ID为0~N-1的Resource

    再重载一下操作符即可,剩下的就是模拟了

    ID好的范围是10000,询问的次数也是10000,里面的hash操作是多余了,自己没有考虑清楚………………

    View Code
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #define MAXN 10010
    using namespace std;
    struct node
    {
    int pri,num;
    bool friend operator<(const node a,const node b)
    {
    if(a.pri!=b.pri)
    return a.pri>b.pri;
    return a.num>b.num;
    }
    };
    int hash1[MAXN],h;
    priority_queue<node> Q[MAXN];
    int main()
    {
    int n,x,y,r,cc;
    char str[10];
    while(scanf("%d",&n)==1)
    {
    h=0;
    cc=1;
    for(int i=0;i<=n;i++)
    while(!Q[i].empty())
    Q[i].pop();
    memset(hash1,-1,sizeof(hash1));

    while(n--)
    {
    node temp;
    scanf("%s",str);
    if(str[0]=='R')
    {
    scanf("%d %d",&x,&y);
    if(hash1[x]==-1)
    hash1[x]=h++;
    temp.num=cc++;
    temp.pri=y;
    Q[hash1[x]].push(temp);
    }
    else {
    scanf("%d",&r);
    if(hash1[r]==-1)
    hash1[r]==h++;
    if(Q[hash1[r]].empty())
    printf("No one fits!\n");
    else
    {
    temp = Q[hash1[r]].top();
    printf("%s gets Num %d: %d %d!\n",str,temp.num,r,temp.pri);
    Q[hash1[r]].pop();
    }
    }
    }
    }
    return 0;
    }
  • 相关阅读:
    nodejs 核心模块crypto
    es6新特性学习
    nodejs 常用全局包
    ionic+angular+cordova 安卓环境搭建
    谷歌浏览器调试保存到文件
    Linux命令
    Linux中用户管理详解(上)-Linux学习日记
    liunx下忘记root密码的解决方法
    cvCanny的参数
    VC运行时库(/MD、/MT等)
  • 原文地址:https://www.cnblogs.com/nanke/p/2368440.html
Copyright © 2020-2023  润新知