HDU5071 - Chat(STL模拟)
题目描述
略。。。
题解
现场赛的时候真是脑残。。。用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模拟)的更多相关文章
- stl+模拟 CCF2016 4 路径解析
// stl+模拟 CCF2016 4 路径解析 // 一开始题意理解错了.... #include <iostream> #include <string> #include ...
- 【STL+模拟】UVa 506 - System Dependencies
System Dependencies Components of computer systems often have dependencies--other components that m ...
- HDU - 5071 Chat(模拟)
原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #in ...
- STL——模拟实现空间配置器
目录 问题 SGI版本空间配置器-std::alloc 一级空间配置器 二级空间配置器 Refill.chunkAlloc函数 最后,配置器封装的simple_alloc接口 问题 我们在日常编写C+ ...
- 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. ...
- CCF 201403-3 命令行选项 (STL模拟)
问题描述 请你写一个命令行分析程序,用以分析给定的命 令行里包含哪些选项.每个命令行由若干个字符串组成,它们之间恰好由一个空格分隔.这些字符串中的第一个为该命令行工具的名字,由小写字母组成,你的程序 ...
- CCF 201403-2 窗口 (STL模拟)
问题描述 在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标轴分别平行的矩形区域.窗口的边界上的点也属于该窗口.窗口之间有层次的区别,在多于一个窗口重叠的区域里,只会显示位于顶层的窗口里的 ...
- uva 327 Evaluating Simple C Expressions 简易C表达式计算 stl模拟
由于没有括号,只有+,-,++,--,优先级简单,所以处理起来很简单. 题目要求计算表达式的值以及涉及到的变量的值. 我这题使用stl的string进行实现,随便进行练手,用string的erase删 ...
- 牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A
牛客练习赛31 D 神器大师泰兹瑞与威穆 https://ac.nowcoder.com/acm/contest/218/D 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26214 ...
随机推荐
- 神经网络指南Hacker's guide to Neural Networks
Hi there, I'm a CS PhD student at Stanford. I've worked on Deep Learning for a few years as part of ...
- c语言 快排排序
快速排序(Quick Sort): 这个算法的霸气程度从它的名字就可以看出来了.快速排序的应用也是非常广的的,各种类库都可以看到他的身影.这当然与它的“快”是有联系的,正所谓天下武功唯快不破. 快速排 ...
- poi操作oracle数据库导出excel文件
HSSFWorkbook workBook = new HSSFWorkbook();// 创建 一个excel文档对象 HSSFSheet sheet = workBook.createSheet( ...
- Codeforces Round #205 (Div. 2)
A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- hdu2457:DNA repair
AC自动机+dp.问改变多少个字符能让目标串不含病毒串.即走过多少步不经过病毒串终点.又是同样的问题. #include<cstdio> #include<cstring> # ...
- Jquery 弹出提示框输入插件 apprise 修改中文按钮以及使用说明
apprise的使用非常简单,引入js脚本和css <script type="text/javascript" src="/js/apprise-1.5.fu ...
- 【转】零基础写Java知乎爬虫之进阶篇
转自:脚本之家 说到爬虫,使用Java本身自带的URLConnection可以实现一些基本的抓取页面的功能,但是对于一些比较高级的功能,比如重定向的处理,HTML标记的去除,仅仅使用URLConnec ...
- objective-c里的方法指针IMP的用法
SGPopSelectView.h @interface SGPopSelectView : UIView @property (nonatomic, assign) SEL selector; @p ...
- 对于随机变量的标准差standard deviation、样本标准差sample standard deviation、标准误差standard error的解释
参考:http://blog.csdn.net/ysuncn/article/details/1749729
- 【转】APUE学习1:迈出第一步,编译myls.c
原文网址:http://blog.csdn.net/sddzycnqjn/article/details/7252444 注:以下写作风格均学习自潘云登前辈 /******************** ...