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. (转)在JAVA实现DataTable对象(三)——DataTable对象实现

    大家都是行家,我就直接上代码了,我这个代码应该还是能看懂的,嘻嘻…. 1: import java.util.ArrayList; 2: import java.util.List; 3:   6: ...

  2. How do I configure a Wired Ethernet interface

    1.In order to configure the Wired Ethernet interface the MDI must be connected to the PC using the U ...

  3. dede 栏目及子栏目

    结果如图: <ul class="bottom_ul"> {dede:channelartlist } <li><a href="{dede ...

  4. jzoj P1163 生日派对灯

    在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码.这些灯都连接到四个按钮:  按钮1:当按下此按钮,将改变所有的灯:本来亮着的灯就熄灭,本来是 ...

  5. How to execute sudo command in remote host via SSH

    Question: I have an interactive shell script, that at one place needs to ssh to another machine (Ubu ...

  6. 句子相似度_tf/idf

    import mathfrom math import isnanimport pandas as pd#结巴分词,切开之后,有分隔符def jieba_function(sent): import ...

  7. Two Sum IV - Input is a BST LT653

    Given a Binary Search Tree and a target number, return true if there exist two elements in the BST s ...

  8. mybatis学习三 数据库连接池技术

    1.在内存中开辟一块空间,存放多个数据库连接对象.就是Connection的多个实例2. 连接池技术有很多,c3p0,dbcp,druid,以及JDBC Tomcat Pool, JDBC Tomca ...

  9. python入门之字典

    1.字典的基本特征: key-value结构 key唯一,必须为不可变数据类型 value可以不唯一 无序 查找速度快 2.创建一个字典: info={“gaohui”:"IT", ...

  10. SPOJ - NSUBSTR(长度为1-len的字串出现的最大次数

    题意:给你一个字符串,要你输出1-len的字串出现的最大次数. /** @xigua */ #include <stdio.h> #include <cmath> #inclu ...