原题链接

题意:有各种操作,模拟这个程序并输出每次操作的信息

分析:恶心模拟题。。。用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里。因为n很小,其他就暴力模拟了。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define ll long long
#define ull unsigned long long
//#define LOCAL using namespace std;
const int maxn=+;
const int inf=0x3f3f3f3f;
const int mod=1e9+; map<int,ll> C;
//flag标记always on top,T为其优先值
int x,T,A[maxn],N,flag; int find(int a){
for(int i=;i<N;i++)
if(A[i]==a)
return i;
return N;
}
void add(){
scanf("%d",&x);
if(C.count(x)) printf("same priority");
else{
A[N++]=x;
C[x]=;
printf("success");
}
}
void close(){
scanf("%d",&x);
if(C.count(x)){
printf("close %d with %I64d",x,C[x]);
C.erase(x);
if(flag&&T==x) flag=;
int pos=find(x);
for(int i=pos;i<N;i++) A[i]=A[i+];
N--;
}
else printf("invalid priority");
}
void chat(){
scanf("%d",&x);
if(N==) printf("empty");
else{
if(flag) C[T]+=x;
else C[A[]]+=x;
printf("success");
}
}
void roate(){
scanf("%d",&x);
if(x>N||x<) printf("out of range");
else{
int t=A[x-];
for(int i=x-;i;i--) A[i]=A[i-];
A[]=t;
printf("success");
}
}
void prior(){
if(N==) printf("empty");
else{
int pos=,maxx=A[];
for(int i=; i<N; i++){
if(A[i]>maxx){
maxx=A[i];
pos=i;
}
}
int t=A[pos];
for(int i=pos;i;i--) A[i]=A[i-];
A[]=t;
printf("success");
}
}
void choose(){
scanf("%d",&x);
if(C.count(x)){
int pos=find(x);
int t=A[pos];
for(int i=pos;i;i--) A[i]=A[i-];
A[]=t;
printf("success");
}
else printf("invalid priority");
}
void top1(){
scanf("%d",&x);
if(C.count(x)){
T=x;
flag=;
printf("success");
}
else printf("invalid priority");
}
void untop(){
if(flag){
flag=;
printf("success");
}
else printf("no such person");
}
void bye(){
if(N==) return;
if(flag&& C[T]) printf("Bye %d: %I64d\n",T,C[T]);
for(int i=;i<N;i++){
if(flag&& A[i]==T) continue;
if(C[A[i]]) printf("Bye %d: %I64d\n",A[i],C[A[i]]);
}
} int main(){
//ios::sync_with_stdio(false);
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int t,n;
cin>>t;
while(t--)
{
N=T=flag=;
C.clear();
scanf("%d",&n);
char s[];
for(int i=; i<=n; i++){
scanf("%s",s);
printf("Operation #%d: ",i);
if(strcmp(s,"Add")==) add();
else if(strcmp(s,"Chat")==) chat();
else if(strcmp(s,"Close")==) close();
else if(strcmp(s,"Rotate")==) roate();
else if(strcmp(s,"Prior")==) prior();
else if(strcmp(s,"Choose")==) choose();
else if(strcmp(s,"Top")==) top1();
else if(strcmp(s,"Untop")==) untop();
printf(".\n");
}
bye();
}
return ;
}

HDU - 5071 Chat(模拟)的更多相关文章

  1. hdu 5071 Chat(模拟)

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

  2. hdu 5071 Chat(模拟|Splay)

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

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

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

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

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

  5. HDOJ 5071 Chat 模拟

    大模拟: 1>saygoodbye要先对 always on top 的人说 2>对没有说过话的不要说good bye 3>用long long Chat Time Limit: 2 ...

  6. HDU 5071 Chat

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

  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 5071(2014鞍山现场赛B题,大模拟)

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

  9. hdu 5071 vector操作恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=5071 对于每一个窗口,有两个属性:优先级+说过的单词数,支持8个操作:新建窗口,关闭窗口并输出信息,聊天(置顶窗 ...

随机推荐

  1. 我的代码库-Java8实现FTP与SFTP文件上传下载

    有网上的代码,也有自己的理解,代码备份 一般连接windows服务器使用FTP,连接linux服务器使用SFTP.linux都是通过SFTP上传文件,不需要额外安装,非要使用FTP的话,还得安装FTP ...

  2. 基于 __new__ 方法的单例模式

    单例模式定义 首次实例化创建实例化对象 之后的每次实例化都用最初的实例化对象 即单实例模式 __new__ 的原理 __new__ 方法可以在 __init__ 方法执行 这样可以在初始化之前进行一系 ...

  3. 扩展资源服务器解决oauth2 性能瓶颈

    OAuth用户携带token 请求资源服务器资源服务器拦截器 携带token 去认证服务器 调用tokenstore 对token 合法性校验资源服务器拿到token,默认只会含有用户名信息通过用户名 ...

  4. 深度分析Java的枚举类型—-枚举的线程安全性及序列化问题

    原文:深度分析Java的枚举类型--枚举的线程安全性及序列化问题 枚举是如何保证线程安全的 要想看源码,首先得有一个类吧,那么枚举类型到底是什么类呢?是enum吗?答案很明显不是,enum就和clas ...

  5. 洛谷P3740 【[HAOI2014]贴海报】

    (呃...本蒟蒻的第一篇题解qwq)..不废话了讲正题..思路来源于铺地毯(-->传送门)..先算出每一个格子上覆盖的海报并把可见的海报做标记然后算出有多少海报是可见的..但是作为省选题怎么可能 ...

  6. <数据结构基础学习>(一)数组

    一.数组基础 1.数组,即把数据码成一排存放. 数组优点:快速查询. 数组最好应用于“索引有语意”的情况,但并非所有有语意的索引都适用于数组,数组也可以处理“索引没有语意”的情况. 2.增.删.改.查 ...

  7. configure: error: no acceptable C compiler found in $PATH 问题解决

    解决办法: 安装GCC软件套件 [root@localhost ~]# yum install gccLoaded plugins: fastestmirrorLoading mirror speed ...

  8. MVC之 自定义过滤器(ActionFilterAttribute)

    一.自定义Filter 自定义Filter需要继承ActionFilterAttribute抽象类,重写其中需要的方法,来看下ActionFilterAttribute类的方法签名. //表示所有操作 ...

  9. Django 分页器的使用

    Django 分页器的使用 Django作为Python Web开发框架的一哥,提供了企业级网站开发所需要的几乎所有功能,其中就包括自带分页功能.利用Django自带的Paginator类,我们可以很 ...

  10. linux 日常中会用到的命令(持续更新)

    1. grep 比如,我要查看www目录下所有包含   “聊天室”  的文件 grep -rn "聊天室" * 比如我要把  www  目录下所有文件中的    聊天室   替换为 ...