hdu5071 2014 Asia AnShan Regional Contest B Chat
模拟题:
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的更多相关文章
- 2014 Asia AnShan Regional Contest --- HDU 5073 Galaxy
Galaxy Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5073 Mean: 在一条数轴上,有n颗卫星,现在你可以改变k颗 ...
- 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),现在要从 ...
- 2014 Asia AnShan Regional Contest --- HDU 5078 Osu!
Osu! Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5078 Mean: 略. analyse: 签到题,直接扫一遍就得答 ...
- 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] ...
- HDU 5073 Galaxy 2014 Asia AnShan Regional Contest 规律题
推公式 #include <cstdio> #include <cmath> #include <iomanip> #include <iostream> ...
- HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水
简单dp #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- 2014 ACM-ICPC Asia Anshan Regional Contest(Online Version)
题目I - Osu! - HDU 5078 题目分析:最水的一道题吧,求两点间的距离和时间差值的最大比值 #include<stdio.h> #include<math.h> ...
- 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 ...
- UVALive 7143 Room Assignment(组合数学+DP)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
随机推荐
- As3 常用日期工具
package com.lj.utils { import mx.controls.DateField; import mx.controls.dataGridClasses.DataGridColu ...
- Android 数独游戏 记录
Android图形编程基本概念 颜色对象 Color 类 int color = Color.bule //蓝色 int color = Color.argb(255,255,255,255); ...
- Warning: $HADOOP_HOME is deprecated.解决方法
方式1(不推荐):注释hadoop-config.sh中的 if [ "$HADOOP_HOME_WARN_SUPPRESS" = "" ] && ...
- 一个采用python获取股票数据的开源库,相当全,及一些量化投资策略库
tushare: http://tushare.waditu.com/index.html 为什么是Python? 就跟javascript在web领域无可撼动的地位一样,Python也已经在金融量化 ...
- IdTCPServer
IdTCPServer1 Server本身就支持多线程,一个服务端连接多个客户端. IdTCPServer1.Bindings.Add.IP := '127.0.0.1';IdTCPServer1.B ...
- MYSQL数据库性能调优之四:解决慢查询--索引
为什么索引能够提高查询速度?没有索引 检索数据的方式是从头到尾一条一条挨着匹配,这是慢的根本原因:索引类型BTREE:二叉树类型,原理图如下:对表创建一个二叉树,记录中间数据的物理磁盘地址,二叉树检索 ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- 【转载】Windows/Office“神key的来源”(附win8神key)
凡是没有经过微软授权的渠道激活Windows/Office的全部是"D版"!但由于密钥激活更方便快捷,因此很受欢迎.从百度博客到现在,很多网友询问:"神key&q ...
- LDS,LES,LFS,LGS,LSS指令
LDS,LES,LFS,LGS,LSS其指令格式都是 LDS reg16,mem32 其意义是同时给一个段寄存器和一个16位通用寄存器同时赋值 具体如下:reg16=mem32的低字, ...
- thinkPHP 无法create,无法插入数据,提示非法数据对象
4.thinkPHP 无法create,提示非法数据对象解决方法:不要create+add,而用 data[]= '';+add$m_r_fa_account = D('R_fa_account'); ...