HDU - 5071 Chat(模拟)
题意:有各种操作,模拟这个程序并输出每次操作的信息
分析:恶心模拟题。。。用个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(模拟)的更多相关文章
- 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(2014鞍山赛区现场赛B题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 解题报告:一个管理聊天窗口的程序,一共有八种操作,然后要注意的就是Top操作只是把编号为u的窗口 ...
- HDOJ 5071 Chat 模拟
大模拟: 1>saygoodbye要先对 always on top 的人说 2>对没有说过话的不要说good bye 3>用long long Chat Time Limit: 2 ...
- HDU 5071 Chat
题意: CLJ找了很多妹子- (题目好没节操-) 对于CLJ和妹子的聊天对话框 有一下几种操作: add 加一个妹子在聊天窗队列末尾 假设这个妹子已经在队列中则add失败 close 关掉 ...
- 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 ...
- hdu 5071 vector操作恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=5071 对于每一个窗口,有两个属性:优先级+说过的单词数,支持8个操作:新建窗口,关闭窗口并输出信息,聊天(置顶窗 ...
随机推荐
- Quartus prime 16.0 in_system memory content editor 使用
前言 quartus提供了片内存储器的实时查看与修改,而不用编译工程,很棒.你可以方便的查看到存储器中到底存储了什么东西. 流程 1.打开: 2.主界面: 3.设置jtag项之后,查看即可. sign ...
- hdu 2191 (多重背包二进制优化)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191 实现代码: #include<bits/stdc++.h> using namespac ...
- google 搜索关键字技巧
google 搜索关键字技巧 来源 https://www.cnblogs.com/qiudabai/articles/9143328.html inurl: 用于搜索网页上包含的URL. 这个语法 ...
- Android性能优化案例研究
译 者前言: 这是Google的Android开发工程师Romain Guy刊登在个人Blog上的一篇文章.Romain Guy 作为Android图形渲染和系统优化的专家,是Android 4.1中 ...
- uvaLive7303 Aquarium (kruskal)
题意:给R*C的房间,每个房间被左上-右下或右上-左下的墙分割为两个小房间,将分割移除有一定花费,问使所有小房间联通需要的最小花费 把每个房间分成左右(上下?)两个点,判一判,本来就联通的加零边,一个 ...
- Palindrome Function HDU - 6156(数位dp)
要求m-n内在l-r进制下的是回文数的总个数. dp[进制][从第j为开始][目前到达第k位] = 总的方案数 dfs枚举目前的到达的位置,这个数开始的位置,进制,前导零,限制条件,然后枚举的时候如果 ...
- 2018"百度之星"程序设计大赛 - 资格赛hdu6349三原色(最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6349 题目: 三原色图 Time Limit: 1500/1000 MS (Java/Others) ...
- luogu4211 LCA
题目链接 思路 我们换一种求\(dep[lca(i,j)]\)的方法. 将从根到\(i\)的路径上所有点的权值加\(1\),然后求从根节点到j路径上点的权值和.就是\(i\)和\(j\)的\(lca\ ...
- 关于数据结构,剑指offer上面的
我很喜欢那些javascript解决的编程题,感觉非常的有意思.我在博客园上面看到了一个同学的博客,他一共发了34篇剑指offer的编程题,还给出了非常详细的解答. 接下来的工作,我做的就是搬运工,不 ...
- CodeForces - 18A Triangle(数学?)
传送门 题意: 给出三个点的坐标,初始,这三个点可以构成一个三角形. 如果初始坐标可以构成直角三角形,输出"RIGNT". 如果某个点的 x或y 坐标移动一个单位后可以组成直角三角 ...