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 ...
随机推荐
- linux 免交互状态下修改用户密码
当利用某些工具对linux用户进行远程密码更改时,输入[ passwd 用户名 ] 后需要输入两次密码, 但是如果你利用的某些工具无法与linux进行交互的情况下,就没办法变更用户密码了,这个时候可以 ...
- UVa 10075 - Airlines
航线算球面距离,需要经纬度转空间坐标. 任意两点间距离用Floyd求出来,查询时直接查表. #include <cstdio> #include <map> #include ...
- 1346. Intervals of Monotonicity(dp)
1346 简单dp #include <iostream> #include<cstdio> #include<cstring> #include<algor ...
- poj 1905 Expanding Rods (数学 计算方法 二分)
题目链接 题意:将长度为L的棒子卡在墙壁之间.现在因为某种原因,木棒变长了,因为还在墙壁之间,所以弯成了一个弧度,现在求的是弧的最高处与木棒原先的地方的最大距离. 分析: 下面的分析是网上别人的分析: ...
- POJ 2516 最小费用流
依然最小费用最大流模板题 建边麻烦了些 #include <cstdio> #include <cstring> #include <iostream> #incl ...
- JAVA调用易信接口向指定好友推送消息(一)背景需求
众所周知,中国电信内部一直使用易信群进行交流 各种工作交流都在易信群里面沟通 包括投诉处理,障碍报修,拍照上传 最重要的就是每天甚至每个时点的指标完成情况的通报 所以只能用4个字来形容 String ...
- PHPnow 升级后 PHP不支持GD、MySQL
来自http://tunps.com/php-unsupport-gd-and-mysql-after-upgrade-phpnow 最近磁盘格式化误操作后,最近两天都在忙于数据恢复,现在才恢复正常. ...
- asp.net批量发布博客到各大博客平台
新浪博客 http://upload.move.blog.sina.com.cn/blog_rebuild/blog/xmlrpc.php 网易博客 http://os.blog.163.com/ap ...
- Struts框架搭建时所遇到的问题
问题一:Unable to load configuration. - bean - jar:file:/D:/Tomcat%206.0/webapps/bar/WEB-INF 原 因:可 ...
- hdu 4666 Hyperspace(多维度最远曼哈顿距离)
献上博文一篇http://hi.baidu.com/byplane747/item/53ca46c159e654bc0d0a7b8d 设维度为k,维护(1<<k)个优先队列,用来保存0~( ...