hdu 5071(2014鞍山现场赛B题,大模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071
思路:模拟题,没啥可说的,移动的时候需要注意top的变化。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAX_N = (5000 + 500);
struct Girl {
int priority;
__int64 words;
Girl() {}
Girl(int _priority, __int64 _words) : priority(_priority), words(_words) {}
}; struct Queue {
int len, top;
struct Girl girl[MAX_N]; void Init() {
len = 0;
top = -1;
} void Add(int u) {
int tag = 0;
for (int i = 0; i < len; ++i) {
if (girl[i].priority == u) {
tag = 1;
break;
}
}
if (tag) {
puts("same priority.");
return;
}
girl[len++] = Girl(u, 0);
puts("success.");
} void Close(int u) {
int pos = -1;
for (int i = 0; i < len; ++i) {
if (girl[i].priority == u) {
pos = i;
break;
}
}
if (pos == -1) {
puts("invalid priority.");
return;
} printf("close %d with %I64d.\n", girl[pos].priority, girl[pos].words); if (top != -1) {
if (top == pos) top = -1;
else if (top > pos) top--;
} for (int i = pos + 1; i < len; ++i) {
girl[i - 1] = girl[i];
}
--len;
} void Chat(int w) {
if (len == 0) {
puts("empty.");
return;
} puts("success."); if (top == -1) {
girl[0].words += (__int64)w;
} else
girl[top].words += (__int64)w;
} void Rotate(int x) {
if (x < 0 || x >= len) {
puts("out of range.");
return;
} puts("success.");
if (top != -1) {
if (top == x) top = 0;
else if (top < x) top++;
} Girl tmp = girl[x];
for (int i = x; i > 0; --i) girl[i] = girl[i - 1];
girl[0] = tmp;
} void Prior() {
if (len == 0) {
puts("empty.");
return;
} puts("success.");
int max_priority = -1, pos = -1;
for (int i = 0; i < len; ++i) {
if (girl[i].priority > max_priority) max_priority = girl[i].priority, pos = i;
}
if (pos > 0) {
if (top != -1) {
if (top == pos) top = 0;
else if (top < pos) top++;
} Girl tmp = girl[pos];
for (int i = pos; i > 0; --i) {
girl[i] = girl[i - 1];
}
girl[0] = tmp;
}
} void Choose(int u) {
int pos = -1;
for (int i = 0; i < len; ++i) {
if (girl[i].priority == u) {
pos = i;
break;
}
}
if (pos == -1) {
puts("invalid priority.");
return;
} puts("success.");
if (top != -1) {
if (top == pos) top = 0;
else if (top < pos) top++;
} Girl tmp = girl[pos];
for (int i = pos; i > 0; --i) girl[i] = girl[i - 1];
girl[0] = tmp;
} void Top(int u) {
int pos = -1;
for (int i = 0; i < len; ++i) {
if (girl[i].priority == u) {
pos = i;
break;
}
}
if (pos == -1) {
puts("invalid priority.");
return;
} puts("success.");
top = pos;
} void Untop() {
if (top == -1) {
puts("no such person.");
return;
} puts("success.");
top = -1;
} void Bye() {
if (top != -1 && girl[top].words > 0) {
printf("Bye %d: %I64d\n", girl[top].priority, girl[top].words);
} for (int i = 0; i < len; ++i) {
if (i != top && girl[i].words > 0) {
printf("Bye %d: %I64d\n", girl[i].priority, girl[i].words);
}
}
}
} que; int N, u, w, x;
char str[22]; int main()
{
int cas;
scanf("%d", &cas);
while (cas--) { scanf("%d", &N); que.Init(); for (int i = 1; i <= N; ++i) {
scanf("%s", str); printf("Operation #%d: ", i);
if (strcmp(str, "Add") == 0) {
scanf("%d", &u);
que.Add(u);
} else if (strcmp(str, "Close") == 0) {
scanf("%d", &u);
que.Close(u);
} else if (strcmp(str, "Chat") == 0) {
scanf("%d", &w);
que.Chat(w);
} else if (strcmp(str, "Rotate") == 0) {
scanf("%d", &x);
que.Rotate(x - 1);
} else if (strcmp(str, "Prior") == 0) {
que.Prior();
} else if (strcmp(str, "Choose") == 0) {
scanf("%d", &u);
que.Choose(u);
} else if (strcmp(str, "Top") == 0) {
scanf("%d", &u);
que.Top(u);
} else if (strcmp(str, "Untop") == 0) {
que.Untop();
}
} que.Bye();
}
return 0;
}
hdu 5071(2014鞍山现场赛B题,大模拟)的更多相关文章
- hdu 5078 2014鞍山现场赛 水题
http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,由于说了ti<ti+1 //#pragma comment(link ...
- hdu 5078(2014鞍山现场赛 I题)
数据 表示每次到达某个位置的坐标和时间 计算出每对相邻点之间转移的速度(两点间距离距离/相隔时间) 输出最大值 Sample Input252 1 9//t x y3 7 25 9 06 6 37 6 ...
- 2014鞍山现场赛C题HDU5072(素筛+容斥原理)
Coprime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
- hdu 5112 (2014北京现场赛 A题)
给出某个时刻对应的速度 求出相邻时刻的平均速度 输出最大值 Sample Input23 // n2 2 //t v1 13 430 31 52 0 Sample OutputCase #1: 2.0 ...
- hdu 5131 (2014广州现场赛 E题)
题意:对给出的好汉按杀敌数从大到小排序,若相等,按字典序排.M个询问,询问名字输出对应的主排名和次排名.(排序之后)主排名是在该名字前比他杀敌数多的人的个数加1,次排名是该名字前和他杀敌数相等的人的个 ...
- HDU 5120 A Curious Matt(2014北京赛区现场赛A题 简单模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5112 解题报告:扫一遍 #include<cstdio> #include<cstr ...
- hdu 5073 Galaxy(2014 鞍山现场赛)
Galaxy Time Limit: 2000/1000 MS (J ...
- hdu 5003 模拟水题 (2014鞍山网赛G题)
你的一系列得分 先降序排列 再按0.95^(i-1)*ai 这个公式计算你的每一个得分 最后求和 Sample Input12530 478Sample Output984.1000000000 # ...
- hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)
两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积 画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交 Sample Input22 30 00 02 30 05 0 Sam ...
随机推荐
- css-css权威指南学习笔记4
第三章 1.继承的值没有特殊性,甚至连0的特殊性都没有.所以改变超链接的样式一般需要独立声明,无法通过继承改变. 2.层叠--冲突的声明通过这个层叠的过程排序,并由此确定最终的文档表示.这个过程的核心 ...
- 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)
D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- 架构师养成记--4.volatile关键字
volatile修饰的变量可在多个线程间可见. 如下代码,在子线程运行期间主线程修改属性值并不对子线程产生影响,原因是子线程有自己独立的内存空间,其中有主内存中的变量副本. public class ...
- C#的继承
什么是继承:继承是允许重用现有类去创建新类的过程.分类的原则是一个类派生出来的子类具有这个类的所有非私有的属性. 1.继承C#中的类:C#不支持多重继承,C#类始终继承自一个基类(如果未在声明中指定一 ...
- 中软培训第一周复习总结 --简单的HTML 与CSS
一些需要记住的点: day1 HTML格式及简单标签: html 文件一般格式: 1 <html> 2 <head lang="en"> 3 <met ...
- <<< Google hack
使用Google等搜索引擎对某些特定的网络主机漏洞(通常是服务器上的脚本漏洞)进行搜索,以达到快速找到漏洞主机或特定主机的漏洞的目的. 在SEO优化中,通常使用这种技术达到入侵一些网站挂外链之用.黑帽 ...
- [转载]用 grub2 启动 clover.iso 来启动 OS X
这个帖子只用来解决特定问题,是楼主这两天辛苦的结晶,如果你遇到了跟我差不多的情形,你就可以尝试这个解决方案. 特定情景:1.不管你的机器支不支持 UEFI ,反正你现在是用传统 BISO + MBR ...
- gis数据格式转换(数据导入)ConvertFeaCls
本文主要对数据导入等里 常用的不同格式数据创建.转换等 进行代码示例.主要用到IFeatureDataConverter.ConvertFeatureClass方法. 代码如下,难度不大,只是个技巧问 ...
- Google Maps API V3 之 路线服务
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- linux 命令行 光标移动技巧
linux 命令行 光标移动技巧 看一个真正的专家操作命令行绝对是一种很好的体验-光标在单词之间来回穿梭,命令行不同的滚动.在这里强烈建立适应GUI节目的开发者尝试一下在提示符下面工作.但是事情也不是 ...