题目链接: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. document.body的一些用法以及js中的常见问题

    document.body的一些用法以及js中的常见问题 网页可见区域宽: document.body.clientWidth; 网页可见区域高: document.body.clientHeight ...

  2. 执行shell脚本提示“syntax error near unexpected token for((i=0;i&lt;$length;i++))”

    sh脚本例如以下: #!/usr/bin/env bash county="3 4 5 6 7 8 9 10 11 12 16 29 39 44 53 62 72 84 97 115 128 ...

  3. Android面试题收集(有具体答案)

    Android面试题目及其答案 1.Android dvm的进程和Linux的进程, 应用程序的进程是否为同一个概念 DVM指dalivk的虚拟机.每个Android应用程序都在它自己的进程中执行,都 ...

  4. GDI+ Tutorial for Beginners

    原文 GDI+ Tutorial for Beginners GDI+ is next evolution of GDI. Using GDI objects in earlier versions ...

  5. [jQuery] check if an id exists - Google 网上论坛

    [jQuery] check if an id exists - Google 网上论坛 From: http://docs.jquery.com/Frequently_Asked_Questions ...

  6. android优化原理

    时间换时间: 数据的异步载入 分批载入. 开机加速. 时间换空间:  分页. 空间换时间: everything.exe 音乐 图库 在开机启动后, sd卡被挂载 生成数据库. 空间换空间: 8G内存 ...

  7. AJAX - 类型“System.Web.UI.UpdatePanel”不具有名为“FileUpload”的公共属性。

    类型“system.web.ui.updatepanel” 不具有名为“***”的公共属性,其实原因很简单.就是少了一个<ContentTemplate></ContentTempl ...

  8. cPickle.so:: PyUnicodeUCS2_DecodeUTF8

    cPickle.so:: PyUnicodeUCS2_DecodeUTF8错误 Python编译的参数,和Python module(mod_wsgi, pymodwsgi)编译参数不一,导致一些un ...

  9. Spring MVC RedirectAttributes的用法解决办法

    Spring MVC RedirectAttributes的用法很久没发过技术贴了,今天对于一个问题纠结了2小时,遂放弃研究用另一种方法解决,奈何心中一直存在纠结,发帖求解 我先解释下什么是Redir ...

  10. Flexigrid去掉列选择

    Flexigrid中会出现列选择的小黑箭头,有时挺讨厌,想去掉.发现没有控制的地方,于是自己加. 在flexigrid.js中增加 在定义中增加 p = $.extend({ //apply defa ...