模拟题:

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. 我常用的Linux命令

    CD: ..        —-切换到上层目录 ~        —-回到家目录(/home/你的登录名/) LS: -a        —-显示指定目录所有文件,包括文件名以 . 开头的文件 -l  ...

  2. opencv3.0 在 android 上的使用

    下载 OpenCV-3.0.0-android-sdk-1.zip 打开 intellj,新建立一个 android 工程后选择工程属性,导入模块(Import module from externa ...

  3. PDF数据提取------2.相关类介绍

    1.简介 构造数据类型PdfString封装Rect类,PdfAnalyzer类中定义一些PDF解析方法. 2.PdfString类与Rect类 public class PdfString : IC ...

  4. 看过的bootstrap书籍(附下载地址)

    http://yun.baidu.com/share/link?shareid=3820784617&uk=1008683945 以下书籍下载地址. <BootStrap入门教程> ...

  5. ajax 瀑布流实现

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Java ClassLoader 原理详细分析

    一.什么是ClassLoader? 大家都知道,当我们写好一个Java程序之后,不是管是CS还是BS应用,都是由若干个.class文件组织而成的一个完整的Java应用程序,当程序在运行时,即会调用该程 ...

  7. 【转】使用json-lib进行Java和JSON之间的转换

    原文链接:http://www.cnblogs.com/mailingfeng/archive/2012/01/18/2325707.html 1. json-lib是一个java类库,提供将Java ...

  8. 简单版问卷调查系统(Asp.Net+SqlServer2008)

    1.系统主要涉及以下几个表  问卷项目表(Q_Naire) 问卷题目表(Q_Problem) 题目类型表(Q_ProblmeType) 题目选项表(Q_Options) 调查结果表(Q_Answer) ...

  9. 关于Windows Azure 地缘组(Affinity Groups)

    最近在和一些客户和朋友的沟通中,发现Windows Azure地缘组概念很少有了解.我的建议是使用地缘组来优化同一区域内的网络访问速度.如果我的说法有误,欢迎大家指正. 关于“地缘组”的概念(摘自MS ...

  10. Cisco ASA5500系列防火墙恢复IOS全过程

    擦除防火墙配置的命令是write erase而不是erase flash!当ASA5510的flash被erase后,如何将新的IOS拷贝到5510内呢? 如下:1. 当flash被erase后设备会 ...