题目描述

略。。。

题解

现场赛的时候真是脑残。。。用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. 腾讯大讲堂ppt全集

    腾讯大讲堂ppt全集 腾讯大讲堂ppt全集资料下载 腾讯大讲堂ppt1-62资料下载 最新最全的腾讯大讲堂ppt全集 腾讯大讲堂ppt全集资料下载 腾讯大讲堂ppt1-62资料下载地址 http:// ...

  2. html 表单笔记

         表单 表单中主要包括下列元素: button——普通按钮radio ——单选按钮checkbox——复选框select ——下拉式菜单text ——单行文本框textarea——多行文本框s ...

  3. JPA和Hibernate的区别

    JPA Java Persistence API,是Java EE 5的标准ORM接口,也是ejb3规范的一部分. Hibernate,当今很流行的ORM框架,是JPA的一个实现,但是其功能是JPA的 ...

  4. hdu 4939 Stupid Tower Defense ( dp )

    题目链接 题意:给出一条长为n个单位长度的直线,每通过一个单位长度需要t秒. 有3种塔,红塔可以在当前格子每秒造成x点伤害,绿塔可以在之后的格子每秒造成y点伤害, 蓝塔可以使通过单位长度的时间增加z秒 ...

  5. bzoj2245: [SDOI2011]工作安排

    费用流. 这道题的模型比较明显,拆点也是很容易看出来的. #include<cstdio> #include<algorithm> #include<cstring> ...

  6. C#基本知识点-Readonly和Const的区别

    什么是静态常量(Const)和动态常量(Readonly)   先解释下什么是静态常量(Const)以及什么是动态常量(Readonly). 静态常量(Const)是指编译器在编译时候会对常量进行解析 ...

  7. 真正解决ASP.NET每一个页面首次访问超级慢的问题 (转载)

    原文:http://www.afuhao.com/article_articleId-219.shtml 摘要:ASP.NET页面首次打开很慢,但别的页面如果没有访问过,去访问也会慢.你也许认为它是在 ...

  8. UVa 10870 (矩阵快速幂) Recurrences

    给出一个d阶线性递推关系,求f(n) mod m的值. , 求出An-dv0,该向量的最后一个元素就是所求. #include <iostream> #include <cstdio ...

  9. 《C++ Primer 4th》读书笔记 第6章-语句

    原创文章,转载请注明出处: http://www.cnblogs.com/DayByDay/p/3912407.html

  10. MySQL基础之第7章 索引

    第7章 索引 MySQL中,所有的数据类型都可以被索引,包括普通索引,唯一性索引,全文索引,单列索引,多列索引和空间索引等. 7.1.索引简介 7.1.1.索引的含义和特点 BTREE索引,HASH索 ...