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. uva11082 Matrix Decompressing

    网络流 首先算出每行每列的数的和. 每行的值减去c,每列的值减去R 然后每行和每列之间连边,容量为19. 这样一来,(i,j)的流量相当于(i,j)的值-1. 这样就避免了流量为0不对应答案的尴尬情况 ...

  2. Spark(1) - Getting Started with Apache Spark

    Introduction Apache Spark is a general-purpose cluster computing system to process big data workload ...

  3. Vs 引用第三方DLL文件 版本不一致问题 (npoi与memcached中的ICSharpCode.SharpZipLib版本冲突的解决方案)

    最近在 做 MailChimp 与网站功能 集成时,发现 MailChimp 2API 中的 MailChimp.dll  中的依赖项 SerivceStack.Text.dll (版本为3.9.71 ...

  4. 【转】FTS抓包看蓝牙的SDP整个过程

    原文网址:http://blog.sina.com.cn/s/blog_69b5d2a50101f23c.html 1.概述   SDP是蓝牙的Service Discovery Protocol,用 ...

  5. MVC三个IOC注入点之Ninject使用示例

    群里一个技术大牛说MVC有三个注入点,但我只会一个DefaultControllerFactory. 在群友的帮助下,我大致了解了下: IControllerFactory=>IDependen ...

  6. Velocity - 单例还是非单例

    在Velocity1.2版本以后,开发者现在又两种选择来使用Velocity引擎,单例模型(singleton model)和单独实例模型(separate instance model).这是相同的 ...

  7. 【打包成exe安装包文件发布你的程序】使用QT联系人管理系统的例子

    [前言]在 QT数据库使用案列[联系人]-- 使用sqlite和QStringListModel 中,我们写了这个程序,如何将它打包成安装文件发给其他小伙伴呢? 我们使用 nsis-2.46-setu ...

  8. hive的使用和深化理解

    1.hive中的数据最终是存放在hdfs上的 2.hive本身不是关系型数据库,hive执行sql语句时会把sql语句翻译成mapreduce程序,然后将mapreduce程序提交到hadoop集群中 ...

  9. js基础第3天

    仿淘宝搜索框案例(有价值) 判断用户输入事件 正常浏览器:oninput(判断用户输入) ie678浏览器兼容:onpropertychange(因为兼容性问题, ie浏览器678是需要使用这个来判断 ...

  10. NOIP2009 靶形数独

    4.靶形数独 (sudoku.pas/c/cpp) [问题描述] 小城和小华都是热爱数学的好学生, 近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了, ...