题目链接:hdu 5071 Chat

题目大意:模拟题。

。。

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

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

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

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

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <map>
  4. #include <vector>
  5. #include <algorithm>
  6. using namespace std;
  7. const int maxn = 5005;
  8. typedef long long ll;
  9. map<int, ll> C;
  10. int x, N, A[maxn], T, flag;
  11. vector<int> vec;
  12. int find(int a) {
  13. for (int i = 0; i < N; i++)
  14. if (A[i] == a)
  15. return i;
  16. return N;
  17. }
  18. void add () {
  19. scanf("%d", &x);
  20. if (C.count(x))
  21. printf("same priority");
  22. else {
  23. A[N++] = x;
  24. C[x] = 0;
  25. printf("success");
  26. }
  27. }
  28. void close() {
  29. scanf("%d", &x);
  30. if (C.count(x)) {
  31. printf("close %d with %I64d", x, C[x]);
  32. C.erase(x);
  33. if (flag && T == x)
  34. flag = 0;
  35. int pos = find(x);
  36. for (int i = pos; i < N; i++)
  37. A[i] = A[i+1];
  38. N--;
  39. } else
  40. printf("invalid priority");
  41. }
  42. void chat() {
  43. scanf("%d", &x);
  44. if (N == 0)
  45. printf("empty");
  46. else {
  47. if (flag) {
  48. C[T] += x;
  49. vec.push_back(T);
  50. } else {
  51. C[A[0]] += x;
  52. vec.push_back(A[0]);
  53. }
  54. printf("success");
  55. }
  56. }
  57. void rotate() {
  58. scanf("%d", &x);
  59. if (x > N || x < 1)
  60. printf("out of range");
  61. else {
  62. int tmp = A[x-1];
  63. for (int i = x-1; i; i--)
  64. A[i] = A[i-1];
  65. A[0] = tmp;
  66. printf("success");
  67. }
  68. }
  69. void prior() {
  70. if (N == 0)
  71. printf("empty");
  72. else {
  73. int x = A[0], pos = 0;
  74. for (int i = 1; i < N; i++) {
  75. if (A[i] > x) {
  76. x = A[i];
  77. pos = i;
  78. }
  79. }
  80. int tmp = A[pos];
  81. for (int i = pos; i; i--)
  82. A[i] = A[i-1];
  83. A[0] = tmp;
  84. printf("success");
  85. }
  86. }
  87. void choose() {
  88. scanf("%d", &x);
  89. if (C.count(x)) {
  90. int pos = find(x);
  91. int tmp = A[pos];
  92. for (int i = pos; i; i--)
  93. A[i] = A[i-1];
  94. A[0] = tmp;
  95. printf("success");
  96. } else
  97. printf("invalid priority");
  98. }
  99. void top() {
  100. scanf("%d", &x);
  101. if (C.count(x)) {
  102. T = x;
  103. flag = 1;
  104. printf("success");
  105. } else
  106. printf("invalid priority");
  107. }
  108. void untop() {
  109. if (flag) {
  110. flag = 0;
  111. printf("success");
  112. } else
  113. printf("no such person");
  114. }
  115. void solve() {
  116. if (N == 0)
  117. return;
  118. if (flag && C[T])
  119. printf("Bye %d: %I64d\n", T, C[T]);
  120. for (int i = 0; i < N; i++) {
  121. if (flag && A[i] == T)
  122. continue;
  123. if (C[A[i]])
  124. printf("Bye %d: %I64d\n", A[i], C[A[i]]);
  125. }
  126. /*
  127. int t = flag ?
  128. T : A[0];
  129. if (C[t])
  130. printf("Bye %d: %I64d\n", t, C[t]);
  131. for (int i = vec.size() - 1; i >= 0; i--) {
  132. if (C.count(vec[i]) && t != vec[i]) {
  133. printf("Bye %d: %I64d\n", vec[i], C[vec[i]]);
  134. break;
  135. }
  136. }
  137. */
  138. }
  139. int main () {
  140. int cas;
  141. scanf("%d", &cas);
  142. while (cas--) {
  143. N = T = flag = 0;
  144. vec.clear();
  145. C.clear();
  146. int Q;
  147. char op[10];
  148. scanf("%d", &Q);
  149. for (int i = 1; i <= Q; i++) {
  150. scanf("%s", op);
  151. printf("Operation #%d: ", i);
  152. if (strcmp(op, "Add") == 0)
  153. add();
  154. else if (strcmp(op, "Close") == 0)
  155. close();
  156. else if (strcmp(op, "Chat") == 0)
  157. chat();
  158. else if (strcmp(op, "Rotate") == 0)
  159. rotate();
  160. else if (strcmp(op, "Prior") == 0)
  161. prior();
  162. else if (strcmp(op, "Choose") == 0)
  163. choose();
  164. else if (strcmp(op, "Top") == 0)
  165. top();
  166. else if (strcmp(op, "Untop") == 0)
  167. untop();
  168. printf(".\n");
  169. }
  170. solve();
  171. }
  172. return 0;
  173. }

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. HDU 2159 二维费用背包问题

    一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...

  2. Netty源代码学习——ChannelPipeline模型分析

    參考Netty API io.netty.channel.ChannelPipeline A list of ChannelHandlers which handles or intercepts i ...

  3. FindChildControl与FindComponent

    前两天编码遇到了要使用FindChildControl方法获取指定名称的TSpeedButton按钮,结果折腾了半天就是没得结果(基础不扎实,呵呵),于是赶紧搜索了下,补习关于这两个方法的用法. TW ...

  4. IIS Web服务扩展中添加ASP.NET4.0

    问题 服务器上安装了ASP.NET 4.0.30319组件,但是在IIS的Web服务扩展中并没有找到ASP.NET v4.0.30319这项,这导致基于.NET4.0开发的网页都无法正常浏览(404错 ...

  5. JAVA之File类创建对象构造函数传参数需要注意的几点

    java中File类用于创建一个文件对象. 首先看一段代码: 1. package MyText1; import java.io.File; public class MyText1 { publi ...

  6. Apache 服务器

    1.介绍 Apache原来用于小型或试验性Internet网络,后来逐步扩展到各种系统中,对Linux的支持几乎完美.Apache可以支持SSL技术,支持多台虚拟主机.Apache是以进程为基础的结构 ...

  7. JavaScript编程:浏览器对象模型BOM

    4.浏览器对象模型BOM: document.body.offsetwidth可以获取浏览器宽度. Window对象:          窗口操作:            1.moveBy(dx,dy ...

  8. 【开发手记一】老生常谈:简简单单配置ZED板开发环境

    说明:整理之前项目博客,此系列之前发表于与非网 http://www.openhw.org/module/forum/thread-552476-1-1.html 在拿到开发板和配套教材之前,我们小组 ...

  9. accumulate

    accumulate?就是sum up a range of elements.呵呵.这个挺简单的.以下是这个算法的简单介绍: Syntax: #include <numeric>//呵呵 ...

  10. .atitit.web 推送实现解决方式集合(3)----dwr3 Reverse Ajax

    .atitit.web 推送实现解决方式集合(3)----dwr3 Reverse Ajax 1. 原理实现 1 2. Page  添加配置.添加回调函数dwr.engine.setActiveRev ...