模拟题:

add的时候出现过的则不再添加

close的时候会影响到top

rotate(Prior、Choose)的时候会影响到top

 /*===============================================================
* Copyright (C) 2014 All rights reserved.
*
* File Name: hdu5071.cpp
* Author:sunshine
* Created Time: 2014-11-11
*
================================================================*/
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm> using namespace std; #define SUCCESS puts("success.")
#define EMPTY puts("empty.")
#define INVALID puts("invalid priority.")
#define SAME puts("same priority.")
#define OUT_OF_RANGE puts("out of range.")
#define NO_SUCH_PERSON puts("no such person.") const int MAXN = ; struct Node{
int value;
long long word_num;
void set(int t_value){
value = t_value;
word_num = ;
}
}node[MAXN]; int top_u;// -1 is no top, value is the top number
int que_size;
map<int,int>M; void init(){
top_u = -;
que_size = ;
M.clear();
} int find_u_id(int u){
int u_id = -;
for(int i = ;i < que_size;i ++){
if(node[i].value == u){
u_id = i;
break;
}
}
return u_id;
} void Rotate(int x){
if(que_size < x){
OUT_OF_RANGE;
}else{
Node tmp = node[x - ];
for(int i = x - ;i >= ;i --){
node[i + ] = node[i];
}
node[] = tmp;
SUCCESS;
}
} void Prior(){
if(que_size == ){
EMPTY;
}else{
int max_value = -, max_value_id = -;
for(int i = ;i < que_size;i ++){
if(node[i].value > max_value){
max_value = node[i].value;
max_value_id = i;
}
}
Rotate(max_value_id + );
}
} void Choose(int u){
if(M[u] == ){
INVALID;
}else{
int u_id = find_u_id(u);
Rotate(u_id + );
}
} void Top(int u){
if(M[u] == ){
INVALID;
}else{
top_u = u;
SUCCESS;
}
} void Untop(){
if(top_u == -){
NO_SUCH_PERSON;
}else{
top_u = -;
SUCCESS;
}
} void Add(int u){
if(M[u] == ){
SAME;
}else{
M[u] = ;
node[que_size ++].set(u);
SUCCESS;
}
} void Close(int u){
if(M[u] == ){
INVALID;
}else{
M[u] = ;
int u_id = find_u_id(u);
if(u == top_u) top_u = -;
printf("close %d with %I64d.\n", u, node[u_id].word_num);
for(int i = u_id;i < que_size;i ++){
node[i] = node[i+];
}
que_size --;
}
} void Chat(int w){
if(que_size == ){
EMPTY;
}else{
if(top_u != -){
node[find_u_id(top_u)].word_num += w;
}else{
node[].word_num += w;
}
SUCCESS;
}
} void Bye(){
if(que_size == ) return ;
int top_id = -;
if(top_u != -){
top_id = find_u_id(top_u);
if(top_id != - && node[top_id].word_num != ){
printf("Bye %d: %I64d\n",node[top_id].value, node[top_id].word_num);
}
}
for(int i = ;i < que_size;i ++){
if(i == top_id) continue;
if(node[i].word_num == ) continue;
printf("Bye %d: %I64d\n",node[i].value, node[i].word_num);
}
} int main(){
int T, n;
char command[];
scanf("%d",&T);
while(T --){
scanf("%d\n",&n);
init();
for(int i = ;i <= n;i ++){
scanf("%s",command);
printf("Operation #%d: ",i);
if( == strcmp("Prior",command)){
Prior();
}else if( == strcmp("Untop",command)){
Untop();
}else {
int u;
scanf("%d",&u);
if( == strcmp("Add",command)){
Add(u);
}else if( == strcmp("Close",command)){
Close(u);
}else if( == strcmp("Chat",command)){
Chat(u);
}else if( == strcmp("Rotate",command)){
Rotate(u);
}else if( == strcmp("Choose",command)){
Choose(u);
}else if( == strcmp("Top",command)){
Top(u);
}
}
}
Bye();
}
return ;
}

hdu5071 2014 Asia AnShan Regional Contest B Chat的更多相关文章

  1. 2014 Asia AnShan Regional Contest --- HDU 5073 Galaxy

    Galaxy Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5073 Mean: 在一条数轴上,有n颗卫星,现在你可以改变k颗 ...

  2. dp --- 2014 Asia AnShan Regional Contest --- HDU 5074 Hatsune Miku

    Hatsune Miku Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5074 Mean: 有m种音符(note),现在要从 ...

  3. 2014 Asia AnShan Regional Contest --- HDU 5078 Osu!

    Osu! Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5078 Mean: 略. analyse: 签到题,直接扫一遍就得答 ...

  4. hdu5072 2014 Asia AnShan Regional Contest C Coprime

    最后一次参加亚洲区…… 题意:给出n(3 ≤ n ≤ 105)个数字,每个数ai满足1 ≤ ai ≤ 105,求有多少对(a,b,c)满足[(a, b) = (b, c) = (a, c) = 1] ...

  5. HDU 5073 Galaxy 2014 Asia AnShan Regional Contest 规律题

    推公式 #include <cstdio> #include <cmath> #include <iomanip> #include <iostream> ...

  6. HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水

    简单dp #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...

  7. 2014 ACM-ICPC Asia Anshan Regional Contest(Online Version)

    题目I - Osu! - HDU 5078 题目分析:最水的一道题吧,求两点间的距离和时间差值的最大比值 #include<stdio.h> #include<math.h> ...

  8. UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  9. UVALive 7143 Room Assignment(组合数学+DP)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

随机推荐

  1. <面试经典题>输入框的功能测试点分析

    (废话几句:这个是网上找来的一份模板,高亮部分为自己修改内容,且此面试题很像当年高考的“必考题”性质,触类旁通吧) 1. 输入框UI是否预计了输入内容长度(尽量完整的显示输入内容): 2. 输入框之前 ...

  2. SQL求 交集 并集 差集

    故事是这样的….. 故事情节: 表 tb_test 有两列, colA , colB; 求 colA , colB 的并交差集… -- 计算并集 SELECT DISTINCT colB FROM t ...

  3. Python超级程序员使用的开发工具

    我以个人的身份采访了几个顶尖的Python程序员,问了他们以下5个简单的问题: 当前你的主要开发任务是什么? 你在项目中使用的电脑是怎样的? 你使用什么IDE开发? 你将来的计划是什么? 有什么给Py ...

  4. MVC linq To SQL更新数据库操作

    首先在视图中提交数据,使用Html.BeginForm() @using(Html.BeginForm()) { @Html.EditorForModel() //编辑模板.控制器中传过来的数据 &l ...

  5. BIOS启动项中的设备都有哪些

    Floppy 软式磁盘驱动器,简称FDD,也就是我们平时所说的软驱. CD-ROM 不用多说了,大家都知道,这是光盘驱动器,也就是我们平时说得光驱. SCSI SCSI的全名是:Small Compu ...

  6. java 的开源wiki维基系统

    几乎所有 维基 系统的对比网址:   http://www.wikimatrix.org/ XWiki,    第二代wiki. 它里面使用的 velocity 模板语言对j2ee开发相当有参考价值, ...

  7. Android通过tcpdump抓包

    1. 手机要有root权限 2. 下载tcpdump   http://www.strazzere.com/android/tcpdump 3. adb push c:\wherever_you_pu ...

  8. rabbitMQ 远程访问

    AMQP server localhost:5672 closed the connection. Check login credentials: Socket closed root@ruiy-c ...

  9. SOA和Web Service介绍

    博客园中关于SOA和Web Service的介绍 http://www.cnblogs.com/talentbuilder/archive/2010/05/04/1727044.html http:/ ...

  10. CSS单词换行and断词

    背景 某天老板在群里反馈,英文单词为什么被截断了? 很显然,这是我们前端的锅,自行背锅.这个问题太简单了,css里加两行属性,分分钟搞定.   1 2 word–break: keep–all; wo ...