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

HDU2275 Kiki & Little Kiki 1

时间:2016-09-25 06:09:22      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

题解:

multiset的应用

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define ll long long
#define CLR(x) memset(x,0,sizeof x)
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=100010;
const int N=1000+10;
const int mod=9901;

ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
    while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
    return x*f;
}
//-----------------------------------------------------------------------------

int main(){
    char op[6];
    int n,x;
    multiset<int> s;
    multiset<int>::iterator it;
    while(~scanf("%d",&n)){
        s.clear();
        for(int i=1;i<=n;i++){
            scanf("%s%d",op,&x);
            if(strcmp(op,"Push")==0) s.insert(x);
            else{
                if(*s.begin()>x||s.empty()) printf("No Element!\n");
                else{
                    it=s.lower_bound(x);
                    if(*it==x) printf("%d\n",x);
                    else printf("%d\n",*(--it));
                    s.erase(it);
                }
            }
        }
        printf("\n");
    }
    return 0;
}

 

HDU2275 Kiki &amp; Little Kiki 1

标签:

原文地址:http://www.cnblogs.com/byene/p/5904793.html

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