程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu 5071 Chat(模擬|Splay)

hdu 5071 Chat(模擬|Splay)

編輯:C++入門知識

hdu 5071 Chat(模擬|Splay)


Chat

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 571 Accepted Submission(s): 136


Problem Description As everyone knows, DRD has no girlfriends. But as everyone also knows, DRD’s friend ATM’s friend CLJ has many potential girlfriends. One evidence is CLJ’s chatting record.

\

CLJ chats with many girls all the time. Sometimes he begins a new conversation and sometimes he ends a conversation. Sometimes he chats with the girl whZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc2Ugd2luZG93IGlzIG9uIHRoZSB0b3AuPGJyPgo8YnI+CllvdSBjYW4gaW1hZ2luZSBDTEqhr3Mgd2luZG93cyBhcyBhIHF1ZXVlLiBUaGUgZmlyc3QgZ2lybCBpbiB0aGUgcXVldWUgaXMgdGhlIHRvcCBnaXJsIGlmIG5vIG9uZSBpcyChsGFsd2F5cyBvbiB0b3AgobEuPGJyPgo8YnI+ClNpbmNlIENMSiBpcyBzbyBwb3B1bGFyLCBoZSBiZWdpbnMgdG8gYXNzaWduIGEgdW5pcXVlIHBvc2l0aXZlIGludGVnZXIgYXMgcHJpb3JpdHkgZm9yIGV2ZXJ5IGdpcmwuIFRoZSBoaWdoZXIgcHJpb3JpdHkgYSBnaXJsIGhhcywgdGhlIG1vcmUgQ0xKIGxpa2VzIGhlci4gRm9yIGV4YW1wbGUsIEdZWiBoYXMgcHJpb3JpdHkgMTA8c3VwPjk8L3N1cD4sIGFuZCBKWlAgaGFzIHByaW9yaXR5IDEwPHN1cD44PC9zdXA+IHdoaWxlIFNpc3Rl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GUgd2lsbCBhbHdheXMgc2F5IGdvb2QgYnllIHRvIHRoZSBjdXJyZW50IHRvcCBnaXJsIGlmIGhlIGhhcyBzcG9rZW4gdG8gaGVyIGJlZm9yZSBoZSBjbG9zZXMgaXQuCiAKPGJyPgpJbnB1dApUaGUgZmlyc3QgbGluZSBjb250YWlucyBhbiBpbnRlZ2VyIFQgKFQgodwgMTApLCBkZW5vdGluZyB0aGUgbnVtYmVyIG9mIHRoZSB0ZXN0IGNhc2VzLjxicj4KPGJyPgpGb3IgZWFjaCB0ZXN0IGNhc2UsIHRoZSBmaXJzdCBsaW5lIGNvbnRhaW5zIGFuIGludGVnZXIgbigwIDwgbiCh3CA1MDAwKSwgcmVwcmVzZW50aW5nIHRoZSBudW1iZXIgb2Ygb3BlcmF0aW9ucy4gVGhlbiBmb2xsb3cgbiBvcGVyYXRpb25zLCBvbmUgaW4gYSBsaW5lLiBBbGwgdGhlIHBhcmFtZXRlcnMgYXJlIHBvc2l0aXZlIGludGVnZXJzIGJlbG93IDEwPHN1cD45PC9zdXA+LgogCjxicj4KT3V0cHV0Ck91dHB1dCBhbGwgdGhlIGxvZ2dpbmcgY29udGVudHMuCiAKPGJyPgpTYW1wbGUgSW5wdXQKCjxwcmUgY2xhc3M9"brush:java;">1 18 Prior Add 1 Chat 1 Add 2 Chat 2 Top 2 Chat 3 Untop Chat 4 Choose 2 Chat 5 Rotate 2 Chat 4 Close 2 Add 3 Prior Chat 2 Close 1
Sample Output
Operation #1: empty.
Operation #2: success.
Operation #3: success.
Operation #4: success.
Operation #5: success.
Operation #6: success.
Operation #7: success.
Operation #8: success.
Operation #9: success.
Operation #10: success.
Operation #11: success.
Operation #12: success.
Operation #13: success.
Operation #14: close 2 with 8.
Operation #15: success.
Operation #16: success.
Operation #17: success.
Operation #18: close 1 with 11.
Bye 3: 2

HintThis problem description does not relate to any real person in THU. 

Source 2014 Asia AnShan Regional Contest
Recommend liuyiding | We have carefully selected several similar problems for you: 5081 5080 5079 5078 5077 題意: 就是要你寫一個聊天窗口管理系統。支持增加窗口。關閉窗口。管理優先級。。。。。詳細的還是自己讀吧。 思路: 覺得splay可做就用splay做的。功能也是splay最基本的功能。這題需要注意的是。最後Bye的時候是先給置頂的人然後按隊列順序Bye。 詳細見代碼:
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int maxn=100100;
const int INF=0x3f3f3f3f;
//ll sum[maxn<<1];//子結點的和
map mp;
int sz[maxn<<1],pre[maxn<<1],mv[maxn<<1],prr[maxn<<1],ch[maxn<<1][2];//sz記錄子樹規模,pre記錄父結點,val存結點值。ch[k][0],ch[k][1]k的左右兒子。
int val[maxn<<1];
int mi,mo,root,s[maxn<<1];//mi回收內存。mo分配內存。root為根。s為內存池
void Treaval(int x)//Debug部分打出來非常清楚
{
    if(x)
    {
        Treaval(ch[x][0]);
        printf("結點%2d:左兒子 %2d 右兒子 %2d 父結點 %2d size = %2d ,val = %2d \n",x,ch[x][0],ch[x][1],pre[x],sz[x],val[x]);
        Treaval(ch[x][1]);
    }
}
void Debug()
{
    printf("root:%d\n",root);
    Treaval(root);
}
void Newnode(int &rt,int v,int pr,int fa)
{
    if(mi)//注意mi記錄可用空間大小但裡面沒有空間所以要先減減。不然會出錯
        rt=s[--mi];
    else
        rt=mo++;
    ch[rt][0]=ch[rt][1]=0;
    //sum[r]=k;
    pre[rt]=fa;
    prr[rt]=pr;
    sz[rt]=1;
    mv[rt]=rt;
    val[rt]=v;
}
void PushUp(int rt)
{
    int ls,rs;
    if(rt==0)
        return;
    ls=ch[rt][0],rs=ch[rt][1];
    sz[rt]=sz[ls]+sz[rs]+1;
    if(prr[mv[ls]]>prr[mv[rs]])
        mv[rt]=mv[ls];
    else
        mv[rt]=mv[rs];
    if(prr[rt]>prr[mv[rt]])
        mv[rt]=rt;
    //sum[rt]=sum[ls]+sum[rs]+val[rt];
}
void Init()//初始化很重要!
{
    mi=root=0;
    mo=1;
    ch[0][0]=ch[0][1]=pre[0]=sz[0]=mv[0]=prr[0]=0;
    val[0]=0;//建一個虛擬根節點。做標記用。pre==0說明就到根了
    Newnode(root,0,0,0);//建真正的根和右兒子。必須加這兩個虛擬結點。這樣區間操作起來才方便
    Newnode(ch[root][1],0,0,root);
    PushUp(ch[root][1]);
    PushUp(root);
}
void Rotate(int x,int w)//旋轉。w為旋轉方式。0為ZAG(x在右邊)。1為ZIG(x在左邊)。結點為左子樹就右旋。右子樹就左旋
{
    int y=pre[x];
    ch[y][!w]=ch[x][w];//把x往上轉
    pre[ch[x][w]]=y;
    //PushDown(y)
    //PushDown(x)
    if(pre[y])
        ch[pre[y]][ch[pre[y]][1]==y]=x;
    pre[x]=pre[y];
    ch[x][w]=y;
    pre[y]=x;
    PushUp(y);
}
void Splay(int rt,int goal)//goal為目標父結點
{
    int y,w;
    while(pre[rt]!=goal)
    {
        if(pre[pre[rt]]==goal)
            Rotate(rt,ch[pre[rt]][0]==rt);
        else
        {
            y=pre[rt];
            w=(ch[pre[y]][0]==y);
            if(ch[y][w]==rt)
            {
                Rotate(rt,!w);
                Rotate(rt,w);
            }
            else
            {
                Rotate(y,w);
                Rotate(rt,w);
            }
        }
    }
    PushUp(rt);
    if(goal==0)//旋轉到根時更換根結點
        root=rt;
}
int Get_kth(int rt,int k)//取第k個數的標號
{
    int tp=sz[ch[rt][0]]+1;
    if(tp==k)
        return rt;
    if(tp>k)
        return Get_kth(ch[rt][0],k);
    else
        return Get_kth(ch[rt][1],k-tp);
}
int Insert(int pos,int v,int pr)//在pos位置插入一個數
{
    Splay(Get_kth(root,pos),0);//因為前面有一個虛擬結點所以實際插的位置為pos+1
    Splay(Get_kth(root,pos+1),root);
    Newnode(ch[ch[root][1]][0],v,pr,ch[root][1]);
    PushUp(ch[root][1]);
    PushUp(root);
    return ch[ch[root][1]][0];
}
void Delete(int rt)//刪除結點
{
    Splay(rt,0);//先把該點旋轉到根
    int pos=sz[ch[rt][0]];//獲取它前面有多少個數
    Splay(Get_kth(root,pos),0);
    Splay(Get_kth(root,pos+2),root);
    s[mi++]=rt;
    ch[ch[root][1]][0]=0;
    PushUp(ch[root][1]);
    PushUp(root);
}
int main()
{
    int n,op,i,t,pos,rt,top;
    char cmd[15];

    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        Init();
        mp.clear();
        top=-1;
        for(i=1;i<=n;i++)
        {
            scanf("%s",cmd);
            if(!strcmp(cmd,"Add"))
            {
                scanf("%d",&op);
                if(mp.count(op))
                    printf("Operation #%d: same priority.\n",i);
                else
                {
                    pos=mp.size();
                    rt=Insert(pos+1,0,op);
                    mp[op]=rt;
                    printf("Operation #%d: success.\n",i);
                }
            }
            else if(!strcmp(cmd,"Close"))
            {
                scanf("%d",&op);
                if(mp.count(op))
                {
                    printf("Operation #%d: close %d with %d.\n",i,op,val[mp[op]]);
                    Delete(mp[op]);
                    if(top==mp[op])
                        top=-1;
                    mp.erase(op);
                }
                else
                    printf("Operation #%d: invalid priority.\n",i);
            }
            else if(!strcmp(cmd,"Chat"))
            {
                scanf("%d",&op);
                if(top!=-1)
                {
                    val[top]+=op;
                    printf("Operation #%d: success.\n",i);
                }
                else if(mp.size())
                {
                    pos=Get_kth(root,2);
                    val[pos]+=op;
                    printf("Operation #%d: success.\n",i);
                }
                else
                    printf("Operation #%d: empty.\n",i);
            }
            else if(!strcmp(cmd,"Rotate"))
            {
                scanf("%d",&op);
                if(mp.size()>=op)
                {
                    pos=Get_kth(root,op+1);
                    Delete(pos);
                    rt=Insert(1,val[pos],prr[pos]);
                    mp[prr[pos]]=rt;
                    if(pos==top)
                        top=rt;
                    printf("Operation #%d: success.\n",i);
                }
                else
                    printf("Operation #%d: out of range.\n",i);
            }
            else if(!strcmp(cmd,"Prior"))
            {
                if(mp.size())
                {
                    pos=mv[root];
                    Delete(pos);
                    rt=Insert(1,val[pos],prr[pos]);
                    mp[prr[pos]]=rt;
                    if(top==pos)
                        top=rt;
                    printf("Operation #%d: success.\n",i);
                }
                else
                    printf("Operation #%d: empty.\n",i);
            }
            else if(!strcmp(cmd,"Choose"))
            {
                scanf("%d",&op);
                if(mp.count(op))
                {
                    pos=mp[op];
                    Delete(pos);
                    rt=Insert(1,val[pos],prr[pos]);
                    if(top==pos)
                        top=rt;
                    mp[op]=rt;
                    printf("Operation #%d: success.\n",i);
                }
                else
                    printf("Operation #%d: invalid priority.\n",i);
            }
            else if(!strcmp(cmd,"Top"))
            {
                scanf("%d",&op);
                if(mp.count(op))
                {
                    top=mp[op];
                    printf("Operation #%d: success.\n",i);
                }
                else
                    printf("Operation #%d: invalid priority.\n",i);
            }
            else if(!strcmp(cmd,"Untop"))
            {
                if(top!=-1)
                {
                    top=-1;
                    printf("Operation #%d: success.\n",i);
                }
                else
                    printf("Operation #%d: no such person.\n",i);
            }
        }
        if(top!=-1)
        {
            if(val[top])
                printf("Bye %d: %d\n",prr[top],val[top]);
            Delete(top);
        }
        while(sz[root]>2)
        {
            pos=Get_kth(root,2);
            if(val[pos])
                printf("Bye %d: %d\n",prr[pos],val[pos]);
            Delete(pos);
        }
    }
    return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved