码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4557

时间:2014-08-18 10:38:23      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   

http://acm.hdu.edu.cn/showproblem.php?pid=4557

解决一类问题的set用法

bubuko.com,布布扣
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>

using namespace std ;

char na[1005][20] ;

int main()
{
    int T ;
    scanf("%d",&T) ;
    multiset <int> S[25] ;
    for(int cas=1 ;cas<=T ;cas++)
    {
        for(int i=0 ;i<25 ;i++)
            S[i].clear() ;
        int n ;
        scanf("%d",&n) ;
        printf("Case #%d:\n",cas) ;
        int cnt=0 ;
        int num=1 ;
        while(n--)
        {
            char op[5] ;
            scanf("%s",op) ;
            if(op[0]==A)
            {
                int x ;
                scanf("%s%d",na[num],&x) ;
                S[x].insert(num++) ;
                printf("%d\n",++cnt) ;
            }
            else
            {
                int x ;
                scanf("%d",&x) ;
                int flag=0 ;
                for(int i=x ;i<=20 ;i++)
                {
                    if(!S[i].empty())
                    {
                        multiset <int>::iterator it ;
                        it=S[i].lower_bound(1) ;
                        if(it!=S[i].end())
                        {
                            flag=1 ;
                            printf("%s\n",na[*it]) ;
                            S[i].erase(it) ;
                            cnt-- ;
                            break ;
                        }
                    }
                }
                if(!flag)
                {
                    puts("WAIT...") ;
                }
            }
        }
    }
    return 0 ;
}
View Code

 

HDU 4557,布布扣,bubuko.com

HDU 4557

标签:style   blog   http   color   os   io   for   ar   

原文地址:http://www.cnblogs.com/xiaohongmao/p/3918889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!