HDU 5071 Chat
题意:
CLJ找了很多妹子… (题目好没节操…) 对于CLJ和妹子的聊天对话框 有一下几种操作:
add 加一个妹子在聊天窗队列末尾 假设这个妹子已经在队列中则add失败
close 关掉某个妹子的聊天窗体 假设没有这个妹子的对话框则close失败 假设成功要输出和这个妹子说过几个词
chat 和最前面妹子说一些话 假设没有窗体打开则chat失败
rotate 将某个妹子移到最前面 假设寻找妹子时发现超出队列范围则rotate失败
prior 将优先级最高妹子移到最前面 假设没有对话框则prior失败
choose 选择某个妹子移到最前面 假设该妹子不在队列则choose失败
top 选择某个妹子将她的状态变为总在最前 假设妹子不在队列则top失败 假设以前有总在最前的妹子 则代替之
untop 撤销总在最前状态 假设没人总在最前则untop失败
最后依照队列顺序 与每个以前说过话的妹子道别
思路:
模拟题… 写写写…
总在最前是一种状态 要理解 它并不直接改变队伍形状
即 第三个妹子被top 再被untop 这时这个妹子依旧站在第三个位置上
注意几个坑点:
close时候可能关掉的是总在最前的妹子的对话框 这时总在最前也同一时候消失
chat要用__int64存储每一个妹子对话过几个词
最后道别时候应该先于总在最前的妹子道别
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<bitset>
using namespace std;
typedef __int64 LL;
#define M 5010 struct girl {
int prior;
LL word;
} g[M];
int T, n, tot, alwaysontop; int main() {
int i, u, j, success, w, x;
char op[30];
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
tot = 0;
alwaysontop = -1;
for (i = 1; i <= n; i++) {
printf("Operation #%d: ", i);
scanf("%s", op);
if (strcmp(op, "Add") == 0) {
scanf("%d", &u);
success = 1;
for (j = 0; j < tot; j++) {
if (g[j].prior == u) {
success = 0;
break;
}
}
if (success) {
printf("success.\n");
g[tot].prior = u;
g[tot].word = 0;
tot++;
} else
printf("same priority.\n");
} else if (strcmp(op, "Close") == 0) {
scanf("%d", &u);
success = 0;
for (j = 0; j < tot; j++) {
if (g[j].prior == u) {
success = 1;
u = j;
break;
}
}
if (success) {
if (g[u].prior == alwaysontop)
alwaysontop = -1;
printf("close %d with %I64d.\n", g[u].prior, g[u].word);
for (j = u; j < tot; j++)
g[j] = g[j + 1];
tot--;
} else
printf("invalid priority.\n");
} else if (strcmp(op, "Chat") == 0) {
scanf("%d", &w);
if (alwaysontop != -1) {
for (u = 0; u < tot; u++) {
if (g[u].prior == alwaysontop) {
g[u].word += w;
break;
}
}
printf("success.\n");
} else if (tot > 0) {
g[0].word += w;
printf("success.\n");
} else
printf("empty.\n");
} else if (strcmp(op, "Rotate") == 0) {
scanf("%d", &x);
if (x >= 1 && x <= tot) {
x--;
while (x) {
swap(g[x], g[x - 1]);
x--;
}
printf("success.\n");
} else
printf("out of range.\n");
} else if (strcmp(op, "Prior") == 0) {
if (tot) {
u = 0;
for (j = 1; j < tot; j++) {
if (g[j].prior > g[u].prior)
u = j;
}
while (u) {
swap(g[u], g[u - 1]);
u--;
}
printf("success.\n");
} else
printf("empty.\n");
} else if (strcmp(op, "Choose") == 0) {
scanf("%d", &u);
success = 0;
for (j = 0; j < tot; j++) {
if (g[j].prior == u) {
success = 1;
u = j;
break;
}
}
if (success) {
while (u) {
swap(g[u], g[u - 1]);
u--;
}
printf("success.\n");
} else
printf("invalid priority.\n");
} else if (strcmp(op, "Top") == 0) {
scanf("%d", &u);
success = 0;
for (j = 0; j < tot; j++) {
if (g[j].prior == u) {
success = 1;
break;
}
}
if (success) {
alwaysontop = u;
printf("success.\n");
} else
printf("invalid priority.\n");
} else if (strcmp(op, "Untop") == 0) {
if (alwaysontop != -1) {
alwaysontop = -1;
printf("success.\n");
} else
printf("no such person.\n");
}
}
if (alwaysontop != -1) {
for (j = 0; j < tot; j++) {
if (g[j].prior == alwaysontop) {
u = j;
break;
}
}
if (g[u].word)
printf("Bye %d: %I64d\n", g[u].prior, g[u].word);
}
for (j = 0; j < tot; j++) {
if (g[j].word && g[j].prior != alwaysontop) {
printf("Bye %d: %I64d\n", g[j].prior, g[j].word);
}
}
}
return 0;
}
HDU 5071 Chat的更多相关文章
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- 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的窗口 ...
- hdu 5071 Chat(模拟|Splay)
Chat Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Sub ...
- HDU - 5071 Chat(模拟)
原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #in ...
- 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个操作:新建窗口,关闭窗口并输出信息,聊天(置顶窗 ...
- HDOJ 5071 Chat 模拟
大模拟: 1>saygoodbye要先对 always on top 的人说 2>对没有说过话的不要说good bye 3>用long long Chat Time Limit: 2 ...
随机推荐
- Caffe —— Deep learning in Practice
因工作交接须要. 要将caffe用法及总体结构描写叙述清楚. 鉴于也有同学问过我相关内容, 决定在本文中写个简单的tutorial, 方便大家參考. 本文简单的讲几个事情: Caffe能做什么? 为什 ...
- 零积分下载,2014年辛星mysql教程秋季版第一本已经完工,期待您的支持
经过一段时间的不懈努力.终于,2014年辛星mysql教程秋季版的第一本,即夯实基础已经完工,在csdn的下载地址为:去下载地址 ,假设左边地址跪了,能够去http://download.csdn.n ...
- EasyUI - NumberBox组件
效果: html代码: <input type ="text" id ="box"/> JS代码: $(function () { $('#box' ...
- 基于visual Studio2013解决C语言竞赛题之1083人机博弈
题目 解决代码及点评 /************************************************************************/ /* ...
- 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
一.对UITabBar背景和icon图标的一些设置 (1)由于直接给UITabBar设置的背景颜色显示的不纯.半透明的感觉,所以,有时候我们能够直接利用纯色的图片作为背景达到想要的效果. (2)给ic ...
- [置顶] cocos2d-x 3.0游戏开发xcode5帅印博客教学 004.[HoldTail]主角的上下飞行跟移动
cocos2d-x 3.0游戏开发xcode5帅印博客教学 004.[HoldTail]主角的上下飞行跟移动 写给大家的前言,在学习cocos2d-x的时候自己走了很多的弯路,也遇到了很多很多问题,不 ...
- javascript (九)注释
单行注释,采用双斜杠 // 多行注释,采用 /* */
- Linux内核参数信息(Oracle相关)
命令行:vim /etc/sysctl.conf 查看如下两行的设置值,这里是: kernel.shmall = 2097152 kernel.shmmax = 4294967295 如果系统默认的 ...
- Mina2 研究总结
一.Mina框架. Mina的框架大概是这么个样子: 底层由Java 的NIO 1.0实现 核心架构应该是这样: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZX ...
- 排列-条件求和(Code)
static void Main(string[] args) { // Generate data int arraySize; int[] data; Random rnd; arraySize ...