Sicily-1443
一. 题意:
模拟队列的操作,按优先级pop。如果有元素pop,则其他在队列里面的元素的时间都要加1.如果队头的元素因为优先级不够高而要push回队列的时候,所有元素的时间都不用改变。
二. 注意选中元素最终输出时,本身的时间戳要加1.
三. 代码
//
// main.cpp
// sicily-1443
//
// Created by ashley on 14-10-11.
// Copyright (c) 2014年 ashley. All rights reserved.
// #include <iostream>
#include <deque>
#include <iterator>
using namespace std;
typedef struct
{
int priorty;
int position;
int time;
}node;
int main(int argc, const char * argv[])
{
int cases, size, pos, pri;
int result = ;
cin >> cases;
while (cases--) {
deque<node> myQueue;
cin >> size >> pos;
for (int i = ; i < size; i++) {
cin >> pri;
node newNode = {pri, i, };
myQueue.push_back(newNode);
}
while (!myQueue.empty()) {
node head = myQueue.front();
//cout << head.position << endl;
myQueue.pop_front();
bool canPrint = true;
for (deque<node>::iterator it = myQueue.begin(); it != myQueue.end() ; it++) {
if (it->priorty > head.priorty) {
myQueue.push_back(head);
canPrint = false;
break;
}
}
if (canPrint) {
if (head.position == pos) {
result = head.time + ;
}
for (deque<node>::iterator it = myQueue.begin(); it != myQueue.end(); it++) {
it->time++;
}
}
}
cout << result << endl;
}
return ;
}
Sicily-1443的更多相关文章
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- 大数求模 sicily 1020
Search
- Sicily 1510欢迎提出优化方案
这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...
- BZOJ:1443: [JSOI2009]游戏Game
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1443 反正不看题解我是完全想不出系列…… 先把棋盘黑白染色,也就是同一对角线上颜色相同,使 ...
- 51nod 1443 路径和树(最短路)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1443 1443 路径和树 题目来源: CodeForces ...
- sicily 1063. Who's the Boss
Time Limit: 1sec Memory Limit:32MB Description Several surveys indicate that the taller you are, ...
- poj 1012 & hdu 1443 Joseph(约瑟夫环变形)
题目链接: POJ 1012: id=1012">http://poj.org/problem?id=1012 HDU 1443: pid=1443">http:// ...
- 51nod 1443 路径和树——最短路生成树
题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1443 不只是做一遍最短路.还要在可以选的边里选最短的才行. 以为是 ...
- 51Nod 1443 路径和树 —— dijkstra
题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1443 首先要得到一个最短路树: 注意边权和最小,因为在最短路中,每 ...
随机推荐
- Linux 抓包
tcpdump -i eth1 -s 0 -w eth1_2.log tcp port 8893
- jquery实现锚点动画效果
锚点相信大家都使用过吧!点击后僵硬的切换是不是很不爽呢? 下面分享一个小技巧,根据锚点offset值来实现动画切换 <!DOCTYPE html PUBLIC "-//W3C//DTD ...
- javascript --推箱子
<head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" ...
- Angular ng-repeat 对象和数组遍历
直接上代码 <!DOCTYPE html> <html> <head> <meta name="description" content= ...
- .NET(C#):在数组成员上加入XmlElement特性
原文 www.cnblogs.com/mgen/archive/2011/12/04/2276131.html 当对如下类进行XML序列化时: publicclassa { }; } 结果会是: &l ...
- 怎样从一个DLL中导出一个C++类
原文作者:Alex Blekhman 翻译:朱金灿 原文来源: http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx 译 ...
- SpringMVC深入理解
核心类与接口 - DispatcherServlet 前置控制器- HandlerMapping 请求映射(到Controller)- HandlerAdapter 请求映射(到Controller类 ...
- 动态调用python类和函数
类 class test1(object): def __init__(self): print "i am test1" class test2(object): def __i ...
- Cocos2d-x lua游戏开发之安装Lua到mac系统
注意:mac ox .lua version :5.15 下载lua官网的lua, 注意:最好是5.15下面.5.2的lua不支持table的getn()方法,这让我情何以堪.(获取table长度.相 ...
- c/c++处理参数
直接上代码:涉及函数getopt(),getopt_long() #include <unistd.h> #include <stdlib.h> #include <st ...