hdu 5071 Chat-----2014acm亚洲区域赛鞍山 B题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071

Chat

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 476    Accepted Submission(s): 109

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 whose window is on the top.

You can imagine CLJ’s windows as a queue. The first girl in the queue is the top girl if no one is “always on top ”.

Since CLJ is so popular, he begins to assign a unique positive integer as priority for every girl. The higher priority a girl has, the more CLJ likes her. For example, GYZ has priority 109, and JZP has priority 108 while Sister Soup has
priority 1, and Face Face has priority 2.

As a famous programmer, CLJ leads a group to implement his own WM(window manager). The WM will log CLJ’s operations. Now you are supposed to implement the log system. The general logging format is “Operation #X: LOGMSG.”, where X is the number of the operation
and LOGMSG is the logging message.

There are several kinds of operations CLJ may use:

1.Add u: CLJ opens a new window whose priority is u, and the new window will be the last window in the window queue. This operation will always be successful except the only case in which there is already a window with priority u. If it is
successful, LOGMSG will be “success”. Otherwise LOGMSG will be “same priority”.

2.Close u: CLJ closes a window whose priority is u. If there exists such a window, the operation will be successful and LOGMSG will be “close u with c”, where u is the priority and c is the number of words CLJ has spoken to this window. Otherwise,
LOGMSG will be “invalid priority”. Note that ANY window can be closed.

3.Chat w: CLJ chats with the top window, and he speaks w words. The top window is the first window in the queue, or the “always on top” window (as described below) instead if there exists. If no window is in the queue, LOGMSG will be “empty”,
otherwise the operation can be successful and LOGMSG will be “success”.

4.Rotate x: CLJ performs one or more Alt-Tabs to move the x-th window to the first one in the queue. For example, if there are 4 windows in the queue, whose priorities are 1, 3, 5, 7 respectively and CLJ performs “Rotate 3”, then the window’s
priorities in the queue will become 5, 1, 3, 7. Note that if CLJ wants to move the first window to the head, this operation is still considered “successful”. If x is out of range (smaller than 1 or larger than the size of the queue), LOGMSG will be “out of
range”. Otherwise LOGMSG should be “success”.

5.Prior: CLJ finds out the girl with the maximum priority and then moves the window to the head of the queue. Note that if the girl with the maximum priority is already the first window, this operation is considered successful as well. If the
window queue is empty, this operation will fail and LOGMSG must be “empty”. If it is successful, LOGMSG must be “success”.

6.Choose u: CLJ chooses the girl with priority u and moves the window to the head of the queue.This operation is considered successful if and only if the window with priority u exists. LOGMSG for the successful cases should be “success” and
for the other cases should be “invalid priority”.

7.Top u: CLJ makes the window of the girl with priority u always on top. Always on top is a special state, which means whoever the first girl in the queue is, the top one must be u if u is always on top. As you can see, two girls cannot be
always on top at the same time, so if one girl is always on top while CLJ wants another always on top, the first will be not always on top any more, except the two girls are the same one. Anyone can be always on top. LOGMSG is the same as that of the Choose
operation.

8.Untop: CLJ cancels the “always on top” state of the girl who is always on top. That is, the girl who is always on top now is not in this special state any more. This operation will fail unless there is one girl always on top. If it fails,
LOGMSG should be “no such person”, otherwise should be “success”.

As a gentleman, CLJ will say goodbye to every active window he has ever spoken to at last, “active” here means the window has not been closed so far. The logging format is “Bye u: c” where u is the priority and c is the number of words he has ever spoken to
this window. He will always say good bye to the current top girl if he has spoken to her before he closes it.

Input

The first line contains an integer T (T ≤ 10), denoting the number of the test cases.

For each test case, the first line contains an integer n(0 < n ≤ 5000), representing the number of operations. Then follow n operations, one in a line. All the parameters are positive integers below 109.

Output

Output all the logging contents.

Sample Input

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

Hint

This 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 5077 5076

Statistic | Submit | Discuss | Note

一道纯模拟题,几乎不涉及算法,只要搞清楚几个步骤就行了。

题意懒得打了,盗用下某大神bolg里的图。。。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
using namespace std;
const int MAX=5010;
typedef long long ll;
map<int,bool> vis;
struct Girl{
    int prior;//优先级
    ll word;//CLJ跟她说了多少话
}que[MAX];
int tail,top;
int ATop;
void init(){
    vis.clear();
    tail=0;top=-1;
    ATop=-1;
}
void Add(int u){
    if(vis[u]){
        printf("same priority.\n"); return;
    }
    printf("success.\n");
    vis[u]=1;
    que[tail].prior=u;
    que[tail++].word=0;
}
void Close(int u){
    if(!vis[u]) {printf("invalid priority.\n");return;}
    vis[u]=0;
    int x=0;
    for(int i=0;i<tail;i++){
        if(que[i].prior==u){x=i;break;}
    }
    if(que[x].prior==ATop){
        ATop=-1;
    }
    printf("close %d with %I64d.\n",que[x].prior,que[x].word);
    for(int i=x;i<tail;i++) que[i]=que[i+1];
    tail--;
}
void Chat(int u){//u the number of words
    if(tail==0){printf("empty.\n");return;}
    printf("success.\n");
    if(ATop!=-1){
        for(int i=0;i<tail;i++){
            if(que[i].prior==ATop){
                que[i].word+=u;
                break;
            }
        }
    }
    else que[0].word+=u;
}
void Rotate(int u){
    if(u>=1&&u<=tail){
        u--;
        while(u){swap(que[u],que[u-1]);u--;}
        printf("success.\n");
    }
    else{
        printf("out of range.\n");
    }
}
void Choose(int u){
    if(!vis[u]){
        printf("invalid priority.\n");return;
    }
    else{
        printf("success.\n");
        int x=0;
        for(int i=0;i<tail;i++){
            if(que[i].prior==u){
                x=i;break;
            }
        }
        while(x){swap(que[x],que[x-1]);x--;}
    }
}
void Top(int u){
    if(!vis[u]){
        printf("invalid priority.\n");return;
    }
    else{
        printf("success.\n");
        ATop=u;
    }
}
void Untop(){
    if(ATop==-1){
        printf("no such person.\n");
        return;
    }
    printf("success.\n");
    ATop=-1;return;
}
void Prior(){
    if(tail==0){
        printf("empty.\n");return;
    }
    printf("success.\n");
    int x=0;
    for(int i=0;i<tail;i++){
        if(que[i].prior>que[x].prior){
            x=i;
        }
    }
    while(x){swap(que[x],que[x-1]);x--;}
}
int main(){
   // freopen("in.txt","r",stdin);
    int T;
    scanf("%d",&T);

    char ord[10];
    int u;
    while(T--){
        init();
        int NN;scanf("%d",&NN);
        int nkase=0;
        while(NN--){
            printf("Operation #%d: ",++nkase);
            scanf("%s",ord);
            if(strcmp(ord,"Untop")==0){
                Untop();
            }
            else if(strcmp(ord,"Prior")==0){
                Prior();
            }
            else{
                scanf("%d",&u);
             //   cout<<"ss"<<endl;
              //  cout<<u<<endl;
                if(strcmp(ord,"Add")==0){
                      //  cout<<"sss"<<endl;
                    Add(u);
                }
                else if(strcmp(ord,"Close")==0){
                    Close(u);
                }
                else if(strcmp(ord,"Chat")==0){
                    Chat(u);
                }
                else if(strcmp(ord,"Rotate")==0){
                    Rotate(u);
                }
                else if(strcmp(ord,"Choose")==0){
                    Choose(u);
                }
                else if(strcmp(ord,"Top")==0){
                    Top(u);
                }
            }

        }
             if(ATop!=-1){
                int x=0;
                for(int i=0;i<tail;i++){
                    if(que[i].prior==ATop){
                        x=i;break;
                    }
                }
                if(que[x].word>0){
                    printf("Bye %d: %I64d\n", que[x].prior, que[x].word);
                }
            }
            for(int i=0;i<tail;i++){
                if(que[i].word&&que[i].prior!=ATop){
                    printf("Bye %d: %I64d\n", que[i].prior, que[i].word);
                }
            }
    }
    return 0;
}
时间: 2024-11-05 06:04:05

hdu 5071 Chat-----2014acm亚洲区域赛鞍山 B题的相关文章

2014acm亚洲区域赛陕西赛总结

这次是第一次出来到外面比赛,一切都是很新奇的,带着新奇来到了古城西安,首先感觉就是志愿者一点都不热情,一副爱理不理的,这不是有违我大西北人的热情好客么.直接说比赛吧. 第一天热身赛,出了两道很水很水的的题目外加一道防AK题目,第一道ZY读了题目之后给我讲了意思,我听的不是很清楚,但是听出来了是一道水题,说是给出一些点的坐标,然后最后一个点和第一个点是初始点和结束点,然后让你从第一个点出发到达最后一个点,每次走的距离不超过1000,我想的是先对所有的点排好序,然后找到起点或者终点,开始往最后一个点

hdu 5078 Osu! (2014 acm 亚洲区域赛鞍山 I)

题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5078 Osu! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 180    Accepted Submission(s): 114 Special Judge Problem Description Osu! is a very p

hdu 5024 DFS 2014亚洲区域赛广州网赛

http://acm.hdu.edu.cn/showproblem.php?pid=5024 DFS写的好像质量不太高,昨晚T了,然后睡的时候重新理下思路,今天重写下,750MSAC,太慢了 //#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <stri

2014ACM亚洲区域北京邀请赛总结

16号早上10点,作为一个28k的屌丝,穿着一双人字拖,乘着北京那一不小心说不定就能给挤怀孕的地铁,和小伙伴们一起来到了北师大.算是第三次来北师大了,前两次是北师大校赛和弱校联合集训,不过看到它们的建筑还是好有感觉(实在是太漂亮了!有木有?)这次开幕式里值得一提的是终于见到了北航10大人物中的董适大牛.董大牛虽然已经退役,他对ACM的热情却丝毫不减.董大牛以他那独特的虽略带紧张但不失诙谐幽默的语调,为我们讲了他那4年的ACM奋斗史,以及他在大一的时候如何因为某个女生而走上ACM这条不归路(哈哈)

第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安站

 第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安赛区总结报告 报告人:田思明 队名:ACpioneer 队长:陈志阳,队员:顾振兴,田思明 西安区域赛告下帷幕,我和陈志阳,顾振兴组成的ACpioneer队最终获得了一块宝贵的铜牌.首先要感谢陈志阳和顾振兴两位杰出队友的努力训练和出色表现,我作为一个新人跟着他们学到了很多很多,也十分珍惜和他们在一起的训练,比赛时光,其次要感谢陈志老师,不辞辛劳陪我们5队和6队前往西安参加比赛,还要感谢集训队所有曾经帮过我们的所有队员们,记得cdy

[hdu5136]Yue Fei&#39;s Battle 2014 亚洲区域赛广州赛区J题(dp)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 现场赛的时候由于有个地方有点小问题,没有成功AC,导致与金牌失之交臂. 由于今天下午有点事情,无法打重现,所以下午只是花了十分钟做了一道J题,抢了个FB,2333333333 Yue Fei's Battle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)T

hdu 5071 Chat(模拟)

题目链接:hdu 5071 Chat 题目大意:模拟题...注意最后说bye的时候只要和讲过话的妹子说再见. 解题思路:用一个map记录每个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A和N记录等级的顺序,增加 删除等操作完全可以同过数组上的模拟,时间足够.T和flag标记是否有置顶窗口. #include <cstdio> #include <cstring> #include <map> #include <vector> #include <

2014 acm亚洲区域赛(北京)总结

2014 acm/icpc 亚洲区域赛北京站    第一次到外面去比赛,周五下午做高铁到北京,报到注册后就去找在北京的同学玩了.    周六,上午,随便拉了个cf,我们随便看了下,没有写代码.下午的开幕式就那样,几个领导讲几句话,之后的热身赛,A题是数试题集出现多少次ACM,我们理解为在这题出现了多少次?第一次交了个17,wa掉了,交了个19,又wa了,后来好像又交了个13,都wa掉了,想哭了%>_<%,后面的D题更逗,给一段代码,判断是wa还是TLE,只有一个测试文件,并且样例数<=3

HDU 5071 Chat(2014鞍山B,模拟)

http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 702    Accepted Submission(s): 163 Problem Description As everyone knows, DRD has no girlfr