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
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.
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.
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
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: 2HintThis problem description does not relate to any real person in THU.
事实上这几天真的不想面对这题。弱成逗比。真是令人忧伤。现场赛没出这题全然是由于自己太弱,就是一道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,模拟)的更多相关文章
- HDU 5071 Chat(2014鞍山赛区现场赛B题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 解题报告:一个管理聊天窗口的程序,一共有八种操作,然后要注意的就是Top操作只是把编号为u的窗口 ...
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- hdu 5071 Chat(模拟|Splay)
Chat Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Sub ...
- HDU - 5071 Chat(模拟)
原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #in ...
- HDU 5071 Chat
题意: CLJ找了很多妹子- (题目好没节操-) 对于CLJ和妹子的聊天对话框 有一下几种操作: add 加一个妹子在聊天窗队列末尾 假设这个妹子已经在队列中则add失败 close 关掉 ...
- HDU 5073 Galaxy(2014鞍山赛区现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5073 解题报告:在一条直线上有n颗星星,一开始这n颗星星绕着重心转,现在我们可以把其中的任意k颗星星移 ...
- hdu 5071 Chat-----2014acm亚洲区域赛鞍山 B题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...
- hdu 5071(2014鞍山现场赛B题,大模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...
随机推荐
- Poj2948Martian Mining(记忆化)
链接 这题意好难懂 看得迷迷糊糊 想的也迷迷糊糊 后来睡了会突然想到了..不就是类似以前的矩阵操作 从右下角记忆化 大的由小的推来 dp[i][j] = max(dp[i-1][j]+s1,dp ...
- java的Serialization 机制
基本使用方法 Serialization是指把类或者基本的数据类型持久化(persistence)到数据流(Stream)中,包括文件.字节流.网络数据流. ...
- POJ3921
搜索 每次找出最短路 如果小于等于k 那么必定这里有一点是要被删掉的 枚举这个最短路径上的每一个点 (一般不会超过20) 将其相邻边删除 用dijskra求最短路径并且保存即可 深度搜索 #inclu ...
- [swustoj 1091] 土豪我们做朋友吧
土豪我们做朋友吧(1091) 问题描述: 人都有缺钱的时候,缺钱的时候要是有个朋友肯帮助你,那将是一件非常幸福的事情.有N个人(编号为1到N),一开始他们互相都不认识,后来发生了M件事情,事情分为2个 ...
- c# equals与==的区别
对于值类型,如果对象的值相等,则相等运算符 (==) 返回 true,否则返回 false.对于string 以外的引用类型,如果两个对象引用同一个对象,则 == 返回 true.对于 string ...
- 【C++】【斐波那契】求第几个斐波那契数字。
首先在头文件 whichfibonaccinumber.h 中写了一个使用加法的解法.没有验证输入数字是否小于0. #ifndef WHICHFIBONACCINUMBER_H_ #define WH ...
- Ext入门学习系列(五)表格控件(2)
上节学习了Ext中表格控件,从创建,到定义数据源.绑定显示,大体明白了一个基本的表格控件是怎么实现的.而我们用表格控件多用于从各种数据源接收数据并显示出来,并不是写死的.本章我们就不同数据源的不同实现 ...
- ARM Linux 如何--注册和触发--软中断
1. 注册软中断当然是通过open_softirq 例子如下: void __init init_timers(void) { int err = timer_cpu_notify(&time ...
- xmlns 属性
xmlns 属性 xmlns 属性可以在文档中定义一个或多个可供选择的命名空间.该属性可以放置在文档内任何元素的开始标签中.该属性的值类似于 URL,它定义了一个命名空间,浏览器会将此命名空间用于该属 ...
- mina2
远程通信 Mina2 学习笔记 作者:李少华 邮箱:xiaosanshaoli@126.com QQ:305409913 2010-12-23 初稿 引言... 1 一. Mina ...