首页 > 代码库 > HDU2275 Kiki & Little Kiki 1

HDU2275 Kiki & Little Kiki 1

题解:

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