一.      题意:

模拟队列的操作,按优先级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. sql server 2000 对应 sql server 2005的row_number()、rank()、DENSE_RANK( )、ntile( )等用法

    转自CSDN:http://blog.csdn.net/htl258/article/details/4006717 SQL server 2005新增的几个函数,分别是row_number( ).r ...

  2. iOS 使用UILocalizedIndexedCollation实现区域索引标题(Section Indexed Title)即拼音排序

    UITableView在行数相当多的时候,给人的感觉是非常笨重的.通常为了方便用户使用,采用的方法有:搜索框.按层级展示.区域索引标题. 前两种就不用介绍了,此文就介绍区域索引标题的实现. 区域索引标 ...

  3. 实现单例模式C++版本

    还是先看最简单的C++单例模式 class CSingleton { private: CSingleton(){} static CSingleton *pInstance; public: sta ...

  4. css区分ie6,7,ff

    IE6能识别*,但不能识别 !important,IE7能识别*,也能识别!important;FF不能识别*,但能识别!important; 可以这样区别FF,IE7,IE6: background ...

  5. symbolを見つけられませんの解決策

    类互相调用造成编译时找不到符号symbol 可以同时编译多个文件:

  6. Sublime Text3中最常用的快捷键

    ctrl+D 选词快捷键 反复按这快捷键,可以方便的向下选择相同的词~ alt + shift +2  分2屏  数字为几就是几屏 Alt + F3 可以一次性选择一个文件里面的所有相同的文本进行编辑 ...

  7. [原创]Python批量操作文件,批量合并

    最近几个小伙伴在手动合并一些文本文件,感觉可以用Python批量实现,就有了这段代码 import os import re import sys def printEnter(f1): #每两个文件 ...

  8. 修改win7注册表发挥大容量内存优势

    现在请打开注册表编辑器,找到[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control \Session Manager\MomoryManagement ...

  9. windows中使用Git工具连接GitHub(配置篇)

    Git在源码管理领域目前占很大的比重了,而且开源的项目很多都转到GitHub上面了.例如:jQuery, reddit, Sparkle, curl, Ruby on Rails, node.js,  ...

  10. HDU 5768 Lucky7(CRT+容斥原理)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5768 [题目大意] 求出一个区间内7的倍数中,对于每个ai取模不等于bi的数的个数. [题解] 首 ...