题目描述

略。。。

题解

现场赛的时候真是脑残。。。用splay去写。。写完发现调试不出来。。。然后才发现数据范围才5000。。。不过那时候只有40分钟了。。用数组模拟了速度敲了一发。写完只剩10几分钟了。。。最终也没调试出来。。赛后想了想发现此题用deque真是巨好写。。

代码:

bye是个坑。必须得在队列里并且是说过话的。。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long LL;
#define maxn 1111111
#define MOD 1000000007
deque< pair<int,LL> >arr;
int tp;
void Add(int x)
{
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it)
if(it->first==x)
{
puts("same priority.");
return;
}
arr.push_back(make_pair(x,));
puts("success.");
}
void Close(int x)
{
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it)
if(it->first==x)
{
if(tp==x) tp=;
printf("close %d with %I64d.\n",x,it->second);
arr.erase(it);
return;
}
puts("invalid priority.");
}
void Chat(int x)
{
if(arr.size()==)
{
puts("empty.");
return;
}
if(tp)
{
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it)
if(it->first==tp)
{
it->second+=x;
break;
}
}
else arr.front().second+=x;
puts("success.");
}
void Rotate(int x)
{
if(arr.size()<x||x<)
{
puts("out of range.");
return;
}
int cnt=;
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it,++cnt)
if(cnt==x)
{
pair<int,LL>pa=*it;
arr.erase(it);
arr.push_front(pa);
break;
}
puts("success.");
}
void Prior()
{
if(arr.size()==)
{
puts("empty.");
return;
}
deque< pair<int,LL> >::iterator mx=arr.begin();
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it)
if(mx->first<it->first) mx=it;
pair<int,LL>pa=*mx;
arr.erase(mx);
arr.push_front(pa);
puts("success.");
}
void Choose(int x)
{
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it)
if(it->first==x)
{
pair<int,LL>pa=*it;
arr.erase(it);
arr.push_front(pa);
puts("success.");
return;
}
puts("invalid priority.");
}
void Top(int x)
{
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it)
if(it->first==x)
{
tp=x;
puts("success.");
return;
}
puts("invalid priority.");
}
void Untop()
{
if(!tp)
{
puts("no such person.");
return;
}
tp=;
puts("success.");
}
void Bye()
{
deque< pair<int,LL> >::iterator fuck=arr.end();
if(tp)
{
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it)
if(it->first==tp&&it->second)
{
printf("Bye %d: %I64d\n",tp,it->second);
arr.erase(it);
break;
}
}
for(deque< pair<int,LL> >::iterator it=arr.begin(); it!=arr.end(); ++it)
if(it->second)
{
printf("Bye %d: %I64d\n",it->first,it->second);
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
arr.clear();
tp=;
for(int i=; i<=n; i++)
{
printf("Operation #%d: ",i);
char op[];
int x;
scanf("%s",op);
if(op[]=='A')
{
scanf("%d",&x);
Add(x);
}
else if(op[]=='l')
{
scanf("%d",&x);
Close(x);
}
else if(op[]=='a')
{
scanf("%d",&x);
Chat(x);
}
else if(op[]=='R')
{
scanf("%d",&x);
Rotate(x);
}
else if(op[]=='P') Prior();
else if(op[]=='C')
{
scanf("%d",&x);
Choose(x);
}
else if(op[]=='T')
{
scanf("%d",&x);
Top(x);
}
else Untop();
}
Bye();
}
return ;
}

HDU5071 - Chat(STL模拟)的更多相关文章

  1. stl+模拟 CCF2016 4 路径解析

    // stl+模拟 CCF2016 4 路径解析 // 一开始题意理解错了.... #include <iostream> #include <string> #include ...

  2. 【STL+模拟】UVa 506 - System Dependencies

    System Dependencies  Components of computer systems often have dependencies--other components that m ...

  3. HDU - 5071 Chat(模拟)

    原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #in ...

  4. STL——模拟实现空间配置器

    目录 问题 SGI版本空间配置器-std::alloc 一级空间配置器 二级空间配置器 Refill.chunkAlloc函数 最后,配置器封装的simple_alloc接口 问题 我们在日常编写C+ ...

  5. UVA - 11995 - I Can Guess the Data Structure! STL 模拟

    There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...

  6. CCF 201403-3 命令行选项 (STL模拟)

    问题描述 请你写一个命令行分析程序,用以分析给定的命 令行里包含哪些选项.每个命令行由若干个字符串组成,它们之间恰好由一个空格分隔.这些字符串中的第一个为该命令行工具的名字,由小写字母组成,你的程序 ...

  7. CCF 201403-2 窗口 (STL模拟)

    问题描述 在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标轴分别平行的矩形区域.窗口的边界上的点也属于该窗口.窗口之间有层次的区别,在多于一个窗口重叠的区域里,只会显示位于顶层的窗口里的 ...

  8. uva 327 Evaluating Simple C Expressions 简易C表达式计算 stl模拟

    由于没有括号,只有+,-,++,--,优先级简单,所以处理起来很简单. 题目要求计算表达式的值以及涉及到的变量的值. 我这题使用stl的string进行实现,随便进行练手,用string的erase删 ...

  9. 牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A

    牛客练习赛31 D 神器大师泰兹瑞与威穆 https://ac.nowcoder.com/acm/contest/218/D 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26214 ...

随机推荐

  1. [Codeforces677C]Vanya and Label(组合数学,快速幂)

    题目链接:http://codeforces.com/contest/677/problem/C 题意:给一个字符和数字的映射关系,然后再给一个字符串.问有多少个其他的字符串,使得那些字符串之间相互操 ...

  2. JAVA的核心概念:接口(interface)

    JAVA的核心概念:接口(interface) 接口与类属于同一层次,实际上,接口是一种特殊的抽象类. 如:    interface IA{ }  public interface: 公开接口  与 ...

  3. 1346. Intervals of Monotonicity(dp)

    1346 简单dp #include <iostream> #include<cstdio> #include<cstring> #include<algor ...

  4. Hibernate学习笔记之EHCache的配置

    Hibernate默认二级缓存是不启动的,启动二级缓存(以EHCache为例)需要以下步骤: 1.添加相关的包: Ehcache.jar和commons-logging.jar,如果hibernate ...

  5. 关于Hibernate中的Configuration

    Hibernate中,关于从 Configuration中建立一个SessionFactory常用的可以有两种方法,一种是为Configuration提供hibernate.cfg.xml配置文件,还 ...

  6. 最大流 Dinic + Sap 模板

    不说别的,直接上模板. Dinic+当前弧优化: struct Edge{ int x,y,c,ne; }e[M*]; int be[N],all; int d[N],q[N]; int stack[ ...

  7. Hibernate映射集合属性

    Hibernate要求持久化集合属性字段必须声明为接口,实际的接口可以是java.util.Set,java.util.Collection,java.util.List,java.util.Map, ...

  8. POJ 1276 (多重背包) Cash Machine

    题意: 有n种纸币,已知每种纸币的面值和数量,求所能凑成的不超过cash的最大总面值. 分析: 这道题自己写了一下TLE了,好可耻.. 找了份比较简洁的代码抄过来了..poj1276 #include ...

  9. android调用JPush获取手机的注册码(Cordova环境)

    JPushInterface.addLocalNotification(cordova.getActivity().getApplication().getApplicationContext(), ...

  10. 最简单的视音频播放示例9:SDL2播放PCM

    本文记录SDL播放音频的技术.在这里使用的版本是SDL2.实际上SDL本身并不提供视音频播放的功能,它只是封装了视音频播放的底层API.在Windows平台下,SDL封装了Direct3D这类的API ...