http://acm.hdu.edu.cn/showproblem.php?pid=5071

对于每一个窗口,有两个属性:优先级+说过的单词数,支持8个操作:新建窗口,关闭窗口并输出信息,聊天(置顶窗口加单词),把优先级最高的窗口移到最前,把当前第i个窗口移到最前,把选择的窗口移到最前,把某个窗口置顶,把置顶窗口取消置顶。。。最后按优先级输出每个窗口的优先级以及单词数。。。

数据范围n<=5000…,恶心模拟

主要就是vector的操作,开始的时候没有置顶窗口记得把now置为0,注意每个参数范围为10^9,要用long long 记录单词数

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
typedef pair<int,LL> p2;
vector<p2> p;
int find(int x)
{
for(int i = 0;i < p.size();++i)
if(p[i].first == x)
return i;
return -1;
}
void erase(int x)
{
int i = 0;
for(vector<p2>::iterator it = p.begin();it != p.end();it++,i++){
if(i == x){
p.erase(it);return;
}
}
}
int x,now;
void Add()
{
RD(x);
if(-1 != find(x))
puts("same priority.");
else{
p.push_back(make_pair(x,0));
puts("success.");
}
}
void Close()
{
RD(x);
int cl = find(x);
if(cl == -1)
puts("invalid priority.");
else{
if(x == now)
now = 0;
printf("close %d with %I64d.\n",p[cl].first,p[cl].second);
erase(cl);
}
}
void Chat()
{
RD(x);
if(0 == p.size())
puts("empty.");
else{
if(now)
p[find(now)].second += x;
else
p[0].second += x;
puts("success.");
}
}
void Rotate(int y)
{
if(y < 1 || y > p.size())
puts("out of range.");
else{
p2 erase_p = p[y - 1];
erase(y - 1);
p.insert(p.begin(),erase_p);
puts("success.");
}
}
void Prior()
{
int mx = 0,mx_i = -1;
if(p.size() == 0)
puts("empty.");
else{
for(int i = 0;i < p.size();++i)
if(p[i].first > mx)
mx = p[i].first , mx_i = i;
Rotate(mx_i + 1);
}
}
void Choose()
{
RD(x);
int ch = find(x);
if(ch == -1)
puts("invalid priority.");
else
Rotate(ch + 1);
}
void Top()
{
RD(x);
if(find(x) == -1)
puts("invalid priority.");
else
now = x,puts("success.");
}
void Untop()
{
if(now)
now = 0,puts("success.");
else
puts("no such person.");
}
void Bye()
{
if(now){
x = find(now);
if(p[x].second != 0)
printf("Bye %d: %I64d\n",p[x].first,p[x].second);
erase(x);
}
for(int i=0; i<p.size(); ++i)
if(p[i].second)
printf("Bye %d: %I64d\n",p[i].first,p[i].second);
}
int main() {
string op;
int _,y,n;RD(_);while(_--){
now = 0;
RD(n);
p.clear();
for(int cas = 1;cas <= n;++cas){
cin>>op;
printf("Operation #%d: ",cas);
if(op=="Add")
Add();
else if(op=="Close")
Close();
else if(op=="Chat")
Chat();
else if(op=="Rotate")
RD(y),Rotate(y);
else if(op=="Prior")
Prior();
else if(op=="Choose")
Choose();
else if(op=="Top")
Top();
else if(op=="Untop")
Untop();
}
Bye();
}
return 0;
}

hdu 5071 vector操作恶心模拟的更多相关文章

  1. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

  2. hdu 4930 斗地主恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4930 就是两个人玩斗地主,有8种牌型,单张,一对,三张,三带一,三带对,四带二,四炸,王炸.问先手能否一次出完牌 ...

  3. HDU - 5071 Chat(模拟)

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

  4. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  5. 向量容器vector操作

    1.向量容器vector 1.1 vector说明 进行vector操作前应添加头文件#include<vector>: vector是向量类型,可以容纳许多类型的数据,因此也被称为容器: ...

  6. L3-002 特殊堆栈 (30分) vector容器的模拟、vector容器的一些用法

    vector容器的简单应用,我们可以用vector维护一个有序数组,每次对要插入的数用upper_bound或者lower_bound来 为这个数找一个应该插入到vector的位置.另外再找一个数组来 ...

  7. HDU 5071 Chat(2014鞍山B,模拟)

    http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  8. hdu 4964 恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...

  9. hdu 5071(2014鞍山现场赛B题,大模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...

随机推荐

  1. Liunx history

    Linux中history历史命令使用方法详解   (转) 作者:青藤园来源:|2012-05-10 10:     http://os.51cto.com/art/201205/335040.htm ...

  2. Oracle数据库mybatis 插入空值时报错(with JdbcType OTHER)

    参考文档: 1.https://blog.csdn.net/fishernemo/article/details/27649233 2.http://helgaxu.iteye.com/blog/21 ...

  3. Unknown type name 'NSString' 解决方案

    今天看到个问题,编辑工程提示Unknown type name 'NSString',如下图 导致出现异常的原因是是因为工程中添加了ZipArchive(第三方开源解压缩库) 一般情况下出现“Unkn ...

  4. BZOJ 3331 [BeiJing2013]压力-Tarjan + 树上差分

    Solution Tarjan 点双缩点, 加上树上差分计算. 注意特判... 我特判挂了好久呜呜呜 Code #include<cstdio> #include<cstring&g ...

  5. BZOJ 1391 [CEOI] Order - 网络流 最大流

    Solution 非常简单的建边!!! 但是刚开始的代码不够体现社会主义的优越性, 于是我 .... 惨痛教训啊... 终于到了今天才能够体现社会主义优越性... Code #include<c ...

  6. C++变量存储类别和内存四区

    变量存储类别 变量声明/定义的一般形式: 存储类别 数据类型 变量名 存储类别指的是数据在内存中存储的方法.存储方法分为静态存储和动态存储两大类.标准C语言为变量.常量和函数定义了4种存储类型:ext ...

  7. Best Sightseeing Pair LT1014

    Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and t ...

  8. Max Chunks To Make Sorted II LT768

    This question is the same as "Max Chunks to Make Sorted" except the integers of the given ...

  9. contenteditable设置元素可编辑

    需求背景 实现一个输入框,高度可以随着输入文字的增加而自动增高 有placeholder,输入为空时,显示placeholder 我们知道可以将div的contenteditable设置伪true,将 ...

  10. random库的常见用法

    import random print( random.randint(1,10) ) # 产生 1 到 10 的一个整数型随机数 print( random.random() ) # 产生 0 到 ...