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 首先要得到一个最短路树: 注意边权和最小,因为在最短路中,每 ...
随机推荐
- sql server把一个表中数据复制到另一个表
insert into A(ID,Name,Sex,Address,DID,...) from (select ID,Name,Sex,Address, 5 DID)
- hive 学习笔记精简
创建表: drop table t create table if not exists t (t string) partitioned by (log_date string) row forma ...
- dedecms导入编辑器
<?php GetEditor("info","",450,"Diy"); ?>
- WPF属性与特性的映射(TypeConverter)
1,定义一个类 public class Human { public string Name { get; set; } public Human Child { get; set; } } 2在X ...
- win7系统下连接使用mac 蓝牙键盘(Apple Wireless Keyborad)
这几天买了一个apple wireless keyborad 玩玩,主要是给孩子买了一个ipad 搭配上wireless keyborad让她玩app足够了,就当一部电脑用吧. 看起来挺精致的,可以了 ...
- POJ 1823 Hotel 线段树
题目链接 线段树的区间合并. 和上一题差不多....第三种操作只需要输出maxx[1]的值就可以. #include <iostream> #include <vector> ...
- python练习之list
请用索引取出下面list的指定元素: # -*- coding: utf-8 -*- L = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python' ...
- 写了个小爬虫,为何用上代理ip总是出现错误。
import urllib.request import re import os import random import threading def url_open(url): #在第8到第12 ...
- 走进C标准库(6)——"string.h"中函数的实现memchr
我写的memchr: void *memchr(const void *buf, char ch, unsigned count){ unsigned ; while(*(buf++) != ch & ...
- JQuery DataTable插件
参考文件: http://blog.csdn.net/xuechongyang/article/details/8424897 http://blog.csdn.net/llhwin2010/arti ...