X-man

导航

xiangtan OJ God Lin’s Harem

http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1159

#include<stdio.h>
#include<string.h>
#include<set>
#include<vector>
using namespace std;
struct node
{
    int num;
    int like;
    friend bool operator <(node a, node b)
    {
        if(a.like>b.like)return true;
        if(a.like==b.like&&a.num>b.num)return true;
        return false;
    }
} ex;
set<node>s;
set<node>::iterator it;
vector<int>v;
int a[100010];
int main()
{
    int n,number;
    char c;
    int x,y;
    while(scanf("%d",&n)!=EOF&&n!=0)
    {
        memset(a,0,sizeof(a));
        v.clear();
        s.clear();
        number=0;
        while(n--)
        {
            getchar();
            scanf("%c",&c);
            if(c=='N')
            {
                number++;
                scanf("%d",&x);
                a[number]=x;
                ex.num=number;
                ex.like=x;
                s.insert(ex);
            }
            else if(c=='I')
            {
                scanf("%d %d",&x,&y);
                ex.num=x;
                ex.like=a[x];//原来的喜欢度
                //it=s.find(ex);
                s.erase(ex);
                ex.like+=y;
                a[x]+=y;//新的喜欢度
                s.insert(ex);
                //printf("%d");
            }
            else if(c=='D')
            {
                scanf("%d %d",&x,&y);
                ex.num=x;
                ex.like=a[x];//原来的喜欢度
                //printf("\t%d %d\n",ex.num,ex.like);
                //it=s.find(ex);
                s.erase(ex);
                ex.like-=y;
                a[x]-=y;//新的喜欢度
                s.insert(ex);
            }
            else if(c=='E')
            {
                scanf("%d",&x);
                ex.num=x;
                ex.like=a[x];//原来的喜欢度
                it=s.find(ex);
                s.erase(*it);
            }
            else if(c=='S')
            {
                v.push_back((*s.begin()).num);
            }
            //for(it=s.begin();it!=s.end();it++)
            //printf("%d %d\n",(*it).num,(*it).like);
        }
        int k=0;
        for(int i=0; i<v.size(); i++)
        {
            if(k==0)
            {
                k=1;
                printf("%d",v[i]);
            }
            else printf(" %d",v[i]);
        }
        printf("\n");
    }
    return 0;
}

 

posted on 2013-05-13 17:43  雨钝风轻  阅读(287)  评论(0编辑  收藏  举报