HDOJ 5071 Chat 模拟
大模拟:
1》saygoodbye要先对 always on top 的人说
2》对没有说过话的不要说good bye
3》用long long
Chat
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 337 Accepted Submission(s): 82

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.
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set> using namespace std; typedef long long int LL; const int INF=0x3f3f3f3f; const int HEAD=0;
const int TAIL=6400; struct CHART
{
int pro,front,back;
LL w;
}chat[6500]; int n,x,id;
int alwayson;
set<int> pc;
char cmd[50]; void init()
{
id=1;pc.clear();alwayson=-1;
memset(chat,0,sizeof(chat));
chat[HEAD].front=HEAD; chat[HEAD].back=TAIL;
chat[TAIL].front=HEAD; chat[TAIL].back=TAIL;
chat[HEAD].pro=-INF-1; chat[TAIL].pro=-INF-1;
} void Add(int u)
{
if(pc.count(u))
{
puts("same priority.");
return ;
}
pc.insert(u);
chat[id].w=0; chat[id].pro=u;
chat[id].front=chat[TAIL].front;
chat[id].back=TAIL;
chat[chat[TAIL].front].back=id;
chat[TAIL].front=id;
id++;
puts("success.");
} void Close(int u)
{
if(pc.count(u)==0)
{
puts("invalid priority.");
return ;
}
pc.erase(u);
if(alwayson==u) alwayson=-1;
int pos=HEAD;
for(pos=HEAD;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro==u) break;
}
int bc=chat[pos].back;
int ft=chat[pos].front;
chat[bc].front=ft;
chat[ft].back=bc;
printf("close %d with %I64d.\n",chat[pos].pro,chat[pos].w);
} void Chat(int w)
{
if(chat[HEAD].back==TAIL)
{
puts("empty.");
return ;
}
puts("success.");
int u=-1;
if(alwayson!=-1) u=alwayson;
else u=chat[chat[HEAD].back].pro;
int pos=HEAD;
for(pos=HEAD;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro==u) break;
}
chat[pos].w+=w;
} void Rotate(int x)
{
if(x<1||x>pc.size())
{
puts("out of range.");
return ;
}
puts("success.");
int pos=HEAD,i=0;
for(pos=HEAD;i<x&&pos!=TAIL;pos=chat[pos].back,i++) ;
///split
int bc=chat[pos].back;
int ft=chat[pos].front;
chat[bc].front=ft;
chat[ft].back=bc;
///merge
chat[pos].front=HEAD;
chat[pos].back=chat[HEAD].back;
chat[chat[HEAD].back].front=pos;
chat[HEAD].back=pos;
} void Prior()
{
if(chat[HEAD].back==TAIL)
{
puts("empty.");
return ;
}
puts("success.");
int pos=HEAD;
int mxp=HEAD;
for(pos=HEAD;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro>chat[mxp].pro)
{
mxp=pos;
}
}
pos=mxp;
///split
int bc=chat[pos].back;
int ft=chat[pos].front;
chat[bc].front=ft;
chat[ft].back=bc;
///merge
chat[pos].front=HEAD;
chat[pos].back=chat[HEAD].back;
chat[chat[HEAD].back].front=pos;
chat[HEAD].back=pos;
} void Choose(int u)
{
if(pc.count(u)==0)
{
puts("invalid priority.");
return ;
}
puts("success.");
int pos=HEAD;
for(pos=HEAD;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro==u) break;
}
///split
int bc=chat[pos].back;
int ft=chat[pos].front;
chat[bc].front=ft;
chat[ft].back=bc;
///merge
chat[pos].front=HEAD;
chat[pos].back=chat[HEAD].back;
chat[chat[HEAD].back].front=pos;
chat[HEAD].back=pos;
} void Top(int u)
{
if(pc.count(u)==0)
{
puts("invalid priority.");
return ;
}
puts("success.");
alwayson=u;
} void Untop()
{
if(alwayson==-1)
{
puts("no such person.");
return ;
}
alwayson=-1;
puts("success.");
} void saybyebye()
{
if(alwayson!=-1)
{
int p=HEAD;
for(p=HEAD;p!=TAIL;p=chat[p].back)
{
if(chat[p].pro==alwayson) break;
}
if(chat[p].w) printf("Bye %d: %I64d\n",chat[p].pro,chat[p].w);
}
int pos=HEAD;
for(pos=chat[HEAD].back;pos!=TAIL;pos=chat[pos].back)
{
if(chat[pos].pro!=alwayson&&chat[pos].w)
printf("Bye %d: %I64d\n",chat[pos].pro,chat[pos].w);
}
} int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
init();
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",cmd);
printf("Operation #%d: ",i+1);
if(strcmp(cmd,"Add")==0)
{
int u; scanf("%d",&u);
Add(u);
}
else if(strcmp(cmd,"Close")==0)
{
int u; scanf("%d",&u);
Close(u);
}
else if(strcmp(cmd,"Chat")==0)
{
int u; scanf("%d",&u);
Chat(u);
}
else if(strcmp(cmd,"Rotate")==0)
{
int u; scanf("%d",&u);
Rotate(u);
}
else if(strcmp(cmd,"Prior")==0)
{
Prior();
}
else if(strcmp(cmd,"Choose")==0)
{
int u; scanf("%d",&u);
Choose(u);
}
else if(strcmp(cmd,"Top")==0)
{
int u; scanf("%d",&u);
Top(u);
}
else if(strcmp(cmd,"Untop")==0)
{
Untop();
}
}
saybyebye();
}
return 0;
}
HDOJ 5071 Chat 模拟的更多相关文章
- 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(2014鞍山B,模拟)
http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU - 5071 Chat(模拟)
原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #in ...
- HDU 5071 Chat(2014鞍山赛区现场赛B题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 解题报告:一个管理聊天窗口的程序,一共有八种操作,然后要注意的就是Top操作只是把编号为u的窗口 ...
- HDU 5071 Chat
题意: CLJ找了很多妹子- (题目好没节操-) 对于CLJ和妹子的聊天对话框 有一下几种操作: add 加一个妹子在聊天窗队列末尾 假设这个妹子已经在队列中则add失败 close 关掉 ...
- hdoj 5319 Painter(模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 思路分析:假设颜色R表示为1,颜色B表示为2,颜色G表示为3,因为数据量较小,采用暴力解法即可, ...
- hdu 5071 Chat-----2014acm亚洲区域赛鞍山 B题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 5071(2014鞍山现场赛B题,大模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...
随机推荐
- CSS——图片替换方法比较
图片替换主要是指将文字替换成图片的技术,即在html语句中使用文字,浏览器显示时用对应的图片显示.其意义在于便于做网站优化(SEO),文字才是搜索引擎寻找的主要对象. 经典的替换方法: Fahrner ...
- 谈谈我的iOS学习及分享
iOS可以说是最近几年比较热门和高速发展一个系统,因此iOS开发也变得火热.越来越多的程序员都转向了iOS开发,每个人的学习方法都不同,分享下我的学习经历和见解吧.我之前学习过C++和Qt,Java也 ...
- VS2010/MFC对话框四:为控件添加消息处理函数
为控件添加消息处理函数 创建对话框类和添加控件变量在上一讲中已经讲过,这一讲的主要内容是如何为控件添加消息处理函数. MFC为对话框和控件等定义了诸多消息,我们对它们操作时会触发消息,这些消息最终由消 ...
- 使用FreeType实现矢量字体的粗体、斜体、描边、阴影效果
前言: Freetype是一个跨平台.开源的字体渲染器,网上很多文章介绍,本人就不啰嗦了.本文重点在于实现文章标题所属的各种效果,不是Freetype的基本使用方法介绍文档,所以对于Freetype不 ...
- 1354 - IP Checking(水题)
1354 - IP Checking PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB An I ...
- Java中Volatile的作用
Java中Volatile的作用 看了几篇博客,发现没搞懂.可是简单来说,就是在我们的多线程开发中.我们用Volatile关键字来限定某个变量或者属性时,线程在每次使用变量的时候.都会读取变量改动后的 ...
- listview 拖动item效果实现
listview 拖动item效果实现 效果图如下: 拖拽前: 拖拽后: 首先参考源码中:TouchInterceptor 类,该类会在下面给出: 第一步:主类: /** * */ packag ...
- 浏览器与服务器间的交互(客服端 <---> 服务器)
浏览器与服务器间的交互(客服端 <---> 服务器) 请求--->处理--->响应 对类HttpContext 内部成员的使用 例如 :Request .Response . ...
- Memcache 查看列出所有key方法
参考博文: Memcache 查看列出所有key方法 1. cmd上登录memcache telnet 127.0.0.1 11211 2. 列出所有keys stats items // 这条是命 ...
- HTTPS 中双向认证SSL 协议的具体过程
HTTPS 中双向认证SSL 协议的具体过程: 这里总结为详细的步骤: ① 浏览器发送一个连接请求给安全服务器.② 服务器将自己的证书,以及同证书相关的信息发送给客户浏览器.③ 客户浏览器检查服务器送 ...