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 ...
随机推荐
- C++:类的组合
在类中定义的数据成员一般都是基本数据类型或服复合数据类型.但是还可以根据需要使用 其他类的对象作为正在声明的数据成员.复杂的对象还可以有比较简单的对象一某种方式组合 而成,复杂对象和组成它的简单对象之 ...
- 转TransactionProxyFactoryBean代理事务
<?xml version="1.0" encoding="GBK"?> <!-- 指定Spring配置文件的DTD信息 --> < ...
- AndroidJNI 调用JAVA(转)
转自:http://www.cnblogs.com/likwo/archive/2012/05/21/2512400.html 1. JNIEnv对象 对于本地函数 JNIEXPORT ...
- OSI七层协议
- VS2012安装英文的语言包后,调试的时候提示Unknown error:0x80040d10
https://social.msdn.microsoft.com/Forums/en-US/e11a86ef-3be2-4256-92e9-d12809f2a6ca/error-0x80040d10 ...
- Android开发之执行定时任务AlarmManager,Timer,Thread
1.Thread:使用线程方式2.Timer是java的特性3.AlarmManager:AlarmManager将应用与服务分割开来后,使得应用程序开发者不用 关心具体的服务,而是直接通过Alarm ...
- 好!recover-binary-search-tree(难)& 两种好的空间O(n)解法 & 空间O(1)解法
https://leetcode.com/mockinterview/session/result/xyc51it/https://leetcode.com/problems/recover-bina ...
- I.MX6 Android U-blox miniPCI 4G porting
/************************************************************************** * I.MX6 Android U-blox m ...
- linux - markdown编辑器
1. linux可以用web-qq,http://web2.qq.com,[我们从未放弃成长,这句话挺感动我的.] (禽兽!你怎么在一开始就跑题!?) ————我只要“及时预览”———— 2. htt ...
- 基于Live555,ffmpeg的RTSP播放器直播与点播
基于Live555,ffmpeg的RTSP播放器直播与点播 多路RTSP高清视频播放器下载地址:http://download.csdn.net/detail/u011352914/6604437多路 ...