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 首先要得到一个最短路树: 注意边权和最小,因为在最短路中,每 ...
随机推荐
- 指定hive输出格式
0.11版本以前: sed -e 's/\x01/|/g' file 0.11版本以后: insert overwrite local directory '/opt/aimcpro/libc/tes ...
- python 备份脚本
import osimport timesource= r"out_res.txt"target_dir= r"F:\python\Doc"target=tar ...
- iOS开发蓝牙 蓝牙4.0的各种踩过的坑,希望你们少踩点
1.首先建立这个三个参数 @property (nonatomic,strong)CBCentralManager * manager; @property (nonatomic,strong)CBP ...
- PHP 单列模式实例讲解以及参考网址
1,http://blog.csdn.net/jungsagacity/article/details/7618587 2,http://www.cnblogs.com/lh460795/archiv ...
- Mysql 如何做双机热备和负载均衡 (方法一)
MySQL数据库没有增量备份的机制,但它提供了一种主从备份的机制,就是把主数据库的所有的数据同时写到备份数据库中.实现MySQL数据库的热备份. 下面是具体的主从热备份的步骤:假设主服务器A(mast ...
- 解决jni链接时找不到函数的问题
用jni调用库函数时,经常会碰到link的错误,具体出错信息如下: 08-07 01:42:06.490: E/AndroidRuntime(1665): java.lang.UnsatisfiedL ...
- easyui 验证控件 tooltip message显示位置
找了半天才发现是这个属性在控制,tipPosition:'left',官网那个demo,误人子弟.
- scanf一次给多个变量赋值
本节课程笔记: 一是对多个变量进行赋值,二是对非法输入的值做正确处理(处理方式了解即可,相关函数知识后期讲解),三是美化scanf代码加入输出说明. /* Name:scanf一次给多个变量赋值 Co ...
- Date对象需要注意的点
var today=new Date(); Date对象取得了PC内部时钟的一个快照,并同时返回一个Date对象实例. 注意静态Date对象和Date对象实例的差别,后者包含一个实际的日期值.毫秒为单 ...
- hdu 2563 统计问题
统计问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...