一.      题意:

模拟队列的操作,按优先级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的更多相关文章

  1. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  2. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  3. 大数求模 sicily 1020

        Search

  4. Sicily 1510欢迎提出优化方案

    这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...

  5. BZOJ:1443: [JSOI2009]游戏Game

    原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1443 反正不看题解我是完全想不出系列…… 先把棋盘黑白染色,也就是同一对角线上颜色相同,使 ...

  6. 51nod 1443 路径和树(最短路)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1443 1443 路径和树 题目来源: CodeForces ...

  7. sicily 1063. Who's the Boss

    Time Limit: 1sec    Memory Limit:32MB  Description Several surveys indicate that the taller you are, ...

  8. poj 1012 &amp; hdu 1443 Joseph(约瑟夫环变形)

    题目链接: POJ  1012: id=1012">http://poj.org/problem?id=1012 HDU 1443: pid=1443">http:// ...

  9. 51nod 1443 路径和树——最短路生成树

    题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1443 不只是做一遍最短路.还要在可以选的边里选最短的才行. 以为是 ...

  10. 51Nod 1443 路径和树 —— dijkstra

    题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1443 首先要得到一个最短路树: 注意边权和最小,因为在最短路中,每 ...

随机推荐

  1. java学习之异常笔记

    异常处理使用try catch finally throw throws 如果try中有执行到return后, 也会执行finally中的语句之后再跳出方法. 异常是对于某种错误情况的描述,是告诉方法 ...

  2. IOS UITextField &UITextView

    UITextField 限制textField长度 曾经,以为输入框只是输入字符的,但真的认真为一个登陆界面输入框而改了六七次以后,发现好烦人啊,先谢谢测试的不厌其烦,不杀之恩,不想再用IOS的输入框 ...

  3. System.Web.HttpException: 无法向会话状态服务器发出会话状态请求

    System.Web.HttpException: 无法向会话状态服务器发出会话状态请求.请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器 ...

  4. yii2.0 控制器方法 视图表单 Form表单处理

    假设我们在ArticleController.php下面的actionForm方法中来处理提交的表单 新建立一个 views/Article/article-form.php文件用来作为输入表单 &l ...

  5. php学习笔记(1)

    1.引用文件的方法有两种:require 及 include require 的使用方法如 require("MyRequireFile.php"); .这个函数通常放在 PHP ...

  6. 中国 省会 地级市 经纬度 city array

    <?php $city_arr = array ( '北京' => array ( 'gis_lng' => '116.405285', 'gis_lat' => '39.90 ...

  7. poj 3348 Cows 求凸包面积

    题目链接 大意: 求凸包的面积. #include <iostream> #include <vector> #include <cstdio> #include ...

  8. 如何重启MySQL服务,正确重启mysql

    RedHat Linux (Fedora Core/Cent OS) 1.启动:/etc/init.d/mysqld start 2.停止:/etc/init.d/mysqld stop 3.重启:/ ...

  9. Linux 关机

    1. shutdown shutdown -h now 立刻关机 shutdown -h 22:50 22:50 分的时候关机 shutdown -h +10 10分钟后关机 shutdwon -r ...

  10. Kate Spade_百度百科

    Kate Spade_百度百科 Kate Spade