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 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
 

事实上这几天真的不想面对这题。弱成逗比。真是令人忧伤。现场赛没出这题全然是由于自己太弱,就是一道SB模拟题,当时就想优化常数。结果优成死循环。看来丽洁说得没错,我果然还是sometimes naive。。

题意:

自己读。

分析:

直接用数组O(n^2)模拟。能够用红黑树优化常数,现场赛手写双向链SB了结果死循环。要注意的是最后Bye的时候要先考虑Top。然后就是注意单词拼写,不要搞混下标,敲的时候不SB即可。

/*
*
* Author : fcbruce <fcbruce8964@gmail.com>
*
* Time : Sat 25 Oct 2014 09:30:24 AM CST
*
*/
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10 #ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif #define maxm
#define maxn 8964 using namespace std; struct __chat
{
int u;
long long c;
}chat[maxn]; int TOP,cnt;
map<int,int> MAP; void Add()
{
int u;
scanf("%d",&u);
if (MAP.count(u)!=0)
{
puts("same priority.");
return ;
} MAP[u]=cnt;
chat[cnt].u=u;
chat[cnt].c=0;
cnt++; puts("success.");
} void Close()
{
int u;
scanf("%d",&u);
if (MAP.count(u)==0)
{
puts("invalid priority.");
return ;
} if (TOP==u) TOP=-1;
int the_one=MAP[u];
printf("close %d with "lld".\n",chat[the_one].u,chat[the_one].c);
for (int i=the_one;i<cnt-1;i++)
{
chat[i]=chat[i+1];
MAP[chat[i].u]=i;
}
cnt--; MAP.erase(u);
} void Chat()
{
int w;
scanf("%d",&w); if (cnt==0)
{
puts("empty.");
return ;
} if (TOP!=-1)
chat[MAP[TOP]].c+=w;
else
chat[0].c+=w; puts("success.");
} void Rotate()
{
int x;
scanf("%d",&x);
if (x<1 || x>cnt)
{
puts("out of range.");
return ;
} __chat temp=chat[x-1];
for (int i=x-1;i>0;i--)
{
chat[i]=chat[i-1];
MAP[chat[i].u]=i;
} chat[0]=temp;
MAP[temp.u]=0; puts("success.");
} void Prior()
{
if (cnt==0)
{
puts("empty.");
return ;
} int the_one=0;
for (int i=1;i<cnt;i++)
if (chat[the_one].u<chat[i].u) the_one=i; __chat temp=chat[the_one];
for (int i=the_one;i>0;i--)
{
chat[i]=chat[i-1];
MAP[chat[i].u]=i;
} chat[0]=temp;
MAP[temp.u]=0; puts("success.");
} void Choose()
{
int u;
scanf("%d",&u);
if (MAP.count(u)==0)
{
puts("invalid priority.");
return ;
} int the_one=MAP[u];
__chat temp=chat[the_one]; for (int i=the_one;i>0;i--)
{
chat[i]=chat[i-1];
MAP[chat[i].u]=i;
} chat[0]=temp;
MAP[temp.u]=0; puts("success.");
} void Top()
{
int u;
scanf("%d",&u); if (MAP.count(u)==0)
{
puts("invalid priority.");
return ;
} TOP=u;
puts("success.");
} void Untop()
{
if (TOP==-1)
puts("no such person.");
else
{
TOP=-1;
puts("success.");
}
} char op[233]; int main()
{
#ifdef FCBRUCE
freopen("/home/fcbruce/code/t","r",stdin);
#endif // FCBRUCE int T_T;
scanf("%d",&T_T); while (T_T--)
{
int n;
scanf("%d",&n); TOP=-1;
cnt=0;
MAP.clear(); for (int i=0;i<n;i++)
{
printf("Operation #%d: ",i+1);
scanf("%s",op); if (strcmp(op,"Add")==0)
Add();
else if(strcmp(op,"Close")==0)
Close();
else if(strcmp(op,"Chat")==0)
Chat();
else if(strcmp(op,"Rotate")==0)
Rotate();
else if(strcmp(op,"Prior")==0)
Prior();
else if(strcmp(op,"Choose")==0)
Choose();
else if(strcmp(op,"Top")==0)
Top();
else
Untop();
} if (TOP!=-1)
if (chat[MAP[TOP]].c!=0)
printf("Bye %d: "lld"\n",TOP,chat[MAP[TOP]].c); for (int i=0;i<cnt;i++)
if (chat[i].u!=TOP && chat[i].c>0)
printf("Bye %d: "lld"\n",chat[i].u,chat[i].c);
} return 0;
}

HDU 5071 Chat(2014鞍山B,模拟)的更多相关文章

  1. HDU 5071 Chat(2014鞍山赛区现场赛B题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 解题报告:一个管理聊天窗口的程序,一共有八种操作,然后要注意的就是Top操作只是把编号为u的窗口 ...

  2. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

  3. hdu 5071 Chat(模拟|Splay)

    Chat Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Sub ...

  4. HDU - 5071 Chat(模拟)

    原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #in ...

  5. HDU 5071 Chat

    题意: CLJ找了很多妹子-  (题目好没节操-)  对于CLJ和妹子的聊天对话框  有一下几种操作: add  加一个妹子在聊天窗队列末尾  假设这个妹子已经在队列中则add失败 close  关掉 ...

  6. HDU 5073 Galaxy(2014鞍山赛区现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5073 解题报告:在一条直线上有n颗星星,一开始这n颗星星绕着重心转,现在我们可以把其中的任意k颗星星移 ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others)    M ...

  8. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  9. hdu 5071(2014鞍山现场赛B题,大模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...

随机推荐

  1. everything搜索工具小技巧

    everything工具平时用的也不多,但是有时候使用的时候却总是找不着北. everything支持五种搜索方式,如下图: 正则匹配搜索: 当你选择正则匹配之后,你可能需要匹配某个文件夹里面的某个文 ...

  2. FJOI2007轮状病毒

    不会推公式…… 不会基尔霍夫矩阵…… 不会matrix—tree定理…… 膜拜vfleaking大神…… 题解:http://z55250825.blog.163.com/blog/static/15 ...

  3. Cookie设置HttpOnly,Secure,Expire属性

    在eclipese中创建Web工程时,有个dynamic web module version选项,首先解释下这个选项的意思: http://stackoverflow.com/questions/3 ...

  4. GRIB格式转换心得(转自博客:http://windforestwing.blog.163.com/blog/static/19545412007103084743804/)

    1.wgrib的使用 在cmd命令行下键入wgrib后即可察看wgrib相关命令参数,简要介绍如下: l        Inventory/diagnostic–output selections 详 ...

  5. Android 自动换行流式布局的RadioGroup

    效果图 用法 使用FlowRadioGroup代替RadioGroup 代码 import android.content.Context; import android.util.Attribute ...

  6. 【转】Application.mk 文件语法规范

    原文网址:http://blog.sina.com.cn/s/blog_4c451e0e0100s6q4.html Application.mk file syntax specification A ...

  7. 【转】【cocos2d-x教程】如何使用WebSocket

    介绍 WebSocket是HTML5开始提供的一种浏览器与服务器间进行全双工通讯的网络技术.在WebSocket API中,浏览器和服务器只需要做一个握手的动作,然后,浏览器和服务器之间就形成了一条快 ...

  8. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.9

    (Schur's Theorem) If $A$ is positive, then $$\bex \per(A)\geq \det A. \eex$$ Solution. By Exercise I ...

  9. Print the numbers between 30 to 3000.

    Microsoft Interview Question Developer Program Engineers 看到一个题目比较有意思: Print the numbers between 30 t ...

  10. bzoj 1834 [ZJOI2010]network 网络扩容(MCMF)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1834 [题意] 给定一个有向图,每条边有容量C,扩容费用W,问最大流和使容量增加K的最 ...