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个操作:新建窗口,关闭窗口并输出信息,聊天(置顶窗 ...
随机推荐
- My Brute HDU - 3315(KM || 费用流)
题意: 有S1到Sn这n个勇士要和X1到Xn这n个勇士决斗,初始时,Si的决斗对象是Xi. 如果Si赢了Xi,那么你将获得Vi分,否则你将获得-Vi分. Si和Xi对决时,Si有初始生命Hi,初始攻击 ...
- 直接使用security.basic.path无效|——springboot2.0以上的security的配置
问题 springcloud 版本 为 Finchley.RELEASEspringboot 版本为 2.0.3.RELEASE 现在有需求,/swagger-ui.html 页面需要添加登录认证,但 ...
- 如何保证 spring-boot 和 spring-cloud版本一致
spring-boot 版本 和 spring-cloud版本是一一对应的,很多错误都是由于版本不一致导致的.很多百度的东西太老了, 版本一升级就会出错. spring的jar包依赖关系是最难的,但聪 ...
- 脚本监控web服务器,工作不正常发邮件提醒
背景介绍公司有多个web网站,没有配置监控服务,每天都需要定时检查服务器是否工作正常.低效耗时. 代码片段 #!/bin/bash # Author Jerry.huang (Email:Jerry. ...
- 【mysql】mysql常用语句
返回不重复数据 SELECT DISTINCT user_name,vistor_username FROM KY_FEED_VISTOR WHERE user_name='shenhy' 单独的di ...
- 牛客小白月赛6C-桃花(DFS/BFS求树的直径)
链接:https://www.nowcoder.com/acm/contest/136/C 来源:牛客网 桃花 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言 ...
- C# Winform窗体基础属性
窗口样式: Inco:改图标样式: MaxmizeBox:true:显示右上角最大化按钮: MinmizeBox:true:显示右上角最小化按钮: ShowInco:true:显示左上角小图标: Sh ...
- 【UOJ 351】新年的叶子
http://uoj.ac/problem/351 其实原来看到这题是真的不想做的 毕竟真的特别怕期望题 后来莫名发现自己打了正解 也是很震惊的2333 Description 对于一棵树,每次随 ...
- CF1140E Palindrome-less Arrays
我觉得这道题非常有前途....... 题意:给定一个填了一半的数组,你要把它补完,使之不存在奇回文串,求方案数.字符集为k. n,k<=20w 解:不能有长为三的回文串.也就是不能有两个相隔1的 ...
- vcftools报错:Writing PLINK PED and MAP files ... Error: Could not open temporary file.解决方案
一般来说有两种解决方案. 第一种:添加“--plink-tped”参数: 用vcftools的“--plink”参数生成plink格式文件时,小样本量测试可以正常生成plink格式,用大样本量时产生W ...