hdu 5071 vector操作恶心模拟
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操作恶心模拟的更多相关文章
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- hdu 4930 斗地主恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4930 就是两个人玩斗地主,有8种牌型,单张,一对,三张,三带一,三带对,四带二,四炸,王炸.问先手能否一次出完牌 ...
- HDU - 5071 Chat(模拟)
原题链接 题意:有各种操作,模拟这个程序并输出每次操作的信息 分析:恶心模拟题...用个map记录一下各个等级女孩的谈话数,同时也便于查找权值为u的在不在队列里.因为n很小,其他就暴力模拟了. #in ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- 向量容器vector操作
1.向量容器vector 1.1 vector说明 进行vector操作前应添加头文件#include<vector>: vector是向量类型,可以容纳许多类型的数据,因此也被称为容器: ...
- L3-002 特殊堆栈 (30分) vector容器的模拟、vector容器的一些用法
vector容器的简单应用,我们可以用vector维护一个有序数组,每次对要插入的数用upper_bound或者lower_bound来 为这个数找一个应该插入到vector的位置.另外再找一个数组来 ...
- HDU 5071 Chat(2014鞍山B,模拟)
http://acm.hdu.edu.cn/showproblem.php?pid=5071 Chat Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 4964 恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...
- hdu 5071(2014鞍山现场赛B题,大模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...
随机推荐
- andorid UI事件 监听器
gridlayout.xml <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns ...
- Eclipse中的maven项目搭建
一.eclipse中的maven设置 1.打开“首选项”----> "maven"---->"Installations".用来查看maven的使用 ...
- Java的OOP三大特征之一——继承
Java的OOP三大特征之一——继承 子类继承父类的特征和行为(属性和方法),使得子类具有父类的各种属性和方法.或子类从父类继承方法,使得子类具有父类相同的行为. 特点:在继承关系中,父类更通用.子类 ...
- Luogu 2051[AHOI2009]中国象棋 - DP
Description 在 $n * m$ 的格子上放若干个炮, 使得每个炮都不能攻击到其他炮 Solution 定义数组f[ i ][ j ][ k ] 表示到了第 i 行, 已经有2个炮的列数为 ...
- insert执行错误,怎么样获取具体的错误原因
1.开启debug 2.去runtime里面去找最后执行的SQL
- Spring ApplicationContext(一)初始化过程
Spring 容器 ApplicationContext(一)初始化过程 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) ...
- IOS初级:UITableView
先来看一下tableview 的结构(plain style). -------------------------------------- + header ...
- Twitter 相关APP开发
首先要获取 Consumer Key (API Key), Consumer Secret (API Secret):最好申请Access Token 和Access Token Secret,不然验 ...
- unity延时函数
新建一个工具类 public class DelayToInvoke : MonoBehaviour{ public static IEnumerator DelayToInvokeDo(Action ...
- c#中的as,is和强转
as和强转之间的区别: as转换类型失败时不会抛出异常:强转类型失败时会抛出异常 引入is先对变量进行检验: if (foo is int) { i = (int)foo; } logger log ...