题目链接:hdu 5071 Chat

题目大意:模拟题。

。。

注意最后说bye的时候仅仅要和讲过话的妹子说再见。

解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子。数组A和N记录等级的顺序,添加

删除等操作全然能够同过数组上的模拟,时间足够。

T和flag标记是否有置顶窗体。

#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm> using namespace std; const int maxn = 5005;
typedef long long ll; map<int, ll> C;
int x, N, A[maxn], T, flag;
vector<int> vec; int find(int a) {
for (int i = 0; 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] = 0;
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 = 0; int pos = find(x);
for (int i = pos; i < N; i++)
A[i] = A[i+1];
N--;
} else
printf("invalid priority");
} void chat() {
scanf("%d", &x);
if (N == 0)
printf("empty");
else {
if (flag) {
C[T] += x;
vec.push_back(T);
} else {
C[A[0]] += x;
vec.push_back(A[0]);
}
printf("success");
}
} void rotate() {
scanf("%d", &x);
if (x > N || x < 1)
printf("out of range");
else {
int tmp = A[x-1];
for (int i = x-1; i; i--)
A[i] = A[i-1];
A[0] = tmp;
printf("success");
}
} void prior() {
if (N == 0)
printf("empty");
else {
int x = A[0], pos = 0;
for (int i = 1; i < N; i++) {
if (A[i] > x) {
x = A[i];
pos = i;
}
} int tmp = A[pos];
for (int i = pos; i; i--)
A[i] = A[i-1];
A[0] = tmp;
printf("success");
}
} void choose() {
scanf("%d", &x);
if (C.count(x)) {
int pos = find(x); int tmp = A[pos];
for (int i = pos; i; i--)
A[i] = A[i-1];
A[0] = tmp;
printf("success");
} else
printf("invalid priority");
} void top() {
scanf("%d", &x);
if (C.count(x)) {
T = x;
flag = 1;
printf("success");
} else
printf("invalid priority");
} void untop() {
if (flag) {
flag = 0;
printf("success");
} else
printf("no such person");
} void solve() {
if (N == 0)
return; if (flag && C[T])
printf("Bye %d: %I64d\n", T, C[T]); for (int i = 0; i < N; i++) {
if (flag && A[i] == T)
continue;
if (C[A[i]])
printf("Bye %d: %I64d\n", A[i], C[A[i]]);
} /*
int t = flag ? T : A[0];
if (C[t])
printf("Bye %d: %I64d\n", t, C[t]); for (int i = vec.size() - 1; i >= 0; i--) {
if (C.count(vec[i]) && t != vec[i]) {
printf("Bye %d: %I64d\n", vec[i], C[vec[i]]);
break;
}
}
*/
} int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
N = T = flag = 0;
vec.clear();
C.clear(); int Q;
char op[10];
scanf("%d", &Q);
for (int i = 1; i <= Q; i++) {
scanf("%s", op);
printf("Operation #%d: ", i);
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 if (strcmp(op, "Untop") == 0)
untop();
printf(".\n");
}
solve();
}
return 0;
}

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

  1. hdu 5071 Chat(模拟|Splay)

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

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

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

  3. HDU - 5071 Chat(模拟)

    原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #in ...

  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. linux命令:env

    env | grep DB ~/>env | grep DB KTK_NONDB_LOG=4

  2. high volume logging

    logging 是现在系统中必不可少的组件了.市面上已经有很多很多非常成熟的日志产品,log*系列就是一个典型代表.对于erlang系统来说,也有很多,比如error_logger, disk_log ...

  3. <1> perl概述

    [root@wx03 1]# cat a1.pl $arr=[1,2,3,4,5,6]; print $arr->[4]."\n"; $hash={a=>1,b=> ...

  4. 首款符合PICO-ITX规格的A20开源硬件开发平台

    http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5NzM0MjcyMQ==&appmsgid=10001083&itemidx=2&am ...

  5. accept系统调用内核实现

    用户态对accept的标准使用方法: if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_siz ...

  6. WordPress的用户系统总结

    原文发表自我的个人主页,欢迎大家訪问~转载请保留本段,或注明原文链接:http://www.hainter.com/wordpress-user-module keyword:WordPress,用户 ...

  7. Lazy Math Instructor

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3721   Accepted: 1290 Description A m ...

  8. [SVN] 分支同步、合入主干操作分享

    冲突的解决原则 不是自己修改的地方就使用主干的. 需要特别注意的是: 分支同步主干时,远端(theirs)是主干,本地(mine/working)的是分支: 分支合入主干时,本地(mine/worki ...

  9. Shell 文件包含

    和其他语言一样,Shell 也可以包含外部脚本.这样可以很方便的封装一些公用的代码作为一个独立的文件. Shell 文件包含的语法格式如下: . filename # 注意点号(.)和文件名中间有一空 ...

  10. uva 10129

    主要是求能否形成联通的欧拉回路 并查集+ 欧拉回路判断 一开始用dfs判断联通,死活A不出来,Wa了好多次………哭…… 并查集一次就AC了 感觉还是并查集代码好写一点, 因为dfs还要判断入口在哪里… ...