CodeForces - 799B-T-shirt buying (优先队列)
/*
Name:
Copyright:
Author:
Date: 2018/5/2 16:09:54
Description:优先队列
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN = ;
int price[MAXN];
struct tshirt{
int index, pri;
tshirt(int i){
this->index = i;
this->pri = price[i] ;
};
bool operator <(const tshirt& lpm) const {
return pri > lpm.pri;
}
};
int main()
{
int n;
while (scanf("%d", &n) != EOF) {
priority_queue<tshirt> lev[];
memset(price, , sizeof(price));
for (int i=; i<n; i++)
scanf("%d", &price[i]);
int level;
for (int i=; i<n; i++) {
scanf("%d", &level);
tshirt demo(i);
lev[level].push(demo);
}
for (int i=; i<n; i++) {
scanf("%d", &level);
tshirt demo(i);
lev[level].push(demo);
}
int num, fav;
scanf("%d", &num);
for (int i=; i<num; i++) {
scanf("%d", &fav);
if (lev[fav].empty() ){
cout<<-<<" ";
continue;
}
int value = ;
while (!lev[fav].empty() && !value) {
if (price[lev[fav].top().index] == -) {//去掉重复的
lev[fav].pop();
} else {
value = ;
cout<<lev[fav].top().pri<<" ";
price[lev[fav].top().index] = -;
lev[fav].pop();
}
}
if (!value){
cout<<-<<" ";
}
}
cout<<endl;
}
return ;
}
CodeForces - 799B-T-shirt buying (优先队列)的更多相关文章
- 【codeforces 799B】T-shirt buying
[题目链接]:http://codeforces.com/contest/799/problem/B [题意] 告诉你每个人喜欢的衣服的颜色; 然后告诉你每件衣服的正面和背面的颜色以及它的价格; 只要 ...
- Codeforces I. Producing Snow(优先队列)
题目描述: C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
- T-shirt buying CodeForces - 799B (小根堆+STL)
题目链接 思路: 由于题目说了只有1,2,3,三种色号的衣服,然后开三个对应色号的小根堆, 我是根据pair<int,int> 创建了一个以价格小的优先的优先队列. pair中的另外一个i ...
- Codeforces 799B - T-shirt buying(STL)
题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...
- CodeForces - 799B T-shirt buying 【贪心】
题目链接 http://codeforces.com/problemset/problem/799/B 题意 给出N件衣服 pi 表示 第i件衣服的价格 ai 表示 第i件衣服的前面的颜色 bi 表示 ...
- codeforces 725D . Contest Balloons(贪心+优先队列)
题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...
- [ An Ac a Day ^_^ ] CodeForces 426C Sereja and Swaps 优先队列
题意: 给你一个有n个数的序列 取一个区间 这个区间内的数可以与区间外的值交换k次 问这样的区间最大值是多少 思路: 看数据是200 时间复杂度O(n*n) 应该可以暴力 顺便学习一下优先队列 枚举区 ...
- CodeForces 754D Fedor and coupons (优先队列)
题意:给定n个优惠券,每张都有一定的优惠区间,然后要选k张,保证k张共同的优惠区间最大. 析:先把所有的优惠券按左端点排序,然后维护一个容量为k的优先队列,每次更新优先队列中的最小值,和当前的右端点, ...
- Codeforces 1136D - Nastya Is Buying Lunch - [贪心+链表+map]
题目链接:https://codeforces.com/problemset/problem/1136/D 题意: 给出 $1 \sim n$ 的某个排列 $p$,再给出若干 $(x,y)$ 表示当序 ...
随机推荐
- mysql-5.7.16-linux-glibc2.5-x86_64精简后的主从配置
1.创建复制账号,并授予复制权限CREATE USER 'fansik'@'10.%' IDENTIFIED BY 'fansik';GRANT REPLICATION SLAVE ON *.* TO ...
- python学习之路-第一天-接触python
我的入门就决定用<简明Python教程> <简明Python教程> 1. python的优势 简单:专注于解决问题而不是关注语言本身 易学:容易上手 开源.免费 可移植性非常强 ...
- java MD5Utils 加密工具类
package com.sicdt.library.core.utils; import java.io.File; import java.io.FileInputStream; import ja ...
- linux免密登录配置
第一步:安装openssh-clients yum install -y openssh-clients.x86_64第二步:生成密钥 ssh-keygen第三步:拷贝公钥到其他机器 ssh-copy ...
- 建议50:Python中的高级数据结构
# -*- coding:utf-8 -*- ''' Collection.Array.Heapq.Bisect.Weakref.Copy以及Pprint collections模块包含了内建类型之外 ...
- 各种排序算法-用Python实现
冒泡排序 # 冒泡排序 def bubble_sort(l): length = len(l) # 外层循环 length遍,内层循环少一遍 while length: for j in range( ...
- JSP 导出Excel表格
ES6语法 传入一个table的id,然后在导出excel按钮上加入一个<a href="#" id="buttonId">导出Excel</ ...
- Android深度探索(卷1)HAL与驱动开发 虚拟环境的安装
前言: 最近在看<Android深度探索(卷1)HAL与驱动开发>安装随书带的虚拟环境浪费了很多时间,说是虚拟环境的安装倒不如说是虚拟环境的导入,其实没什么技术含量,也没有什么复杂的,只是 ...
- php二维数组自定义排序
$arr = array( '0' => array('id' =>1,'price'=>200), '1' => array('id' =>2,'price'=> ...
- java 实现HTTP连接(HTTPClient)
在实习中,使用到了http连接,一直理解的很模糊,特地写个分析整理篇.分析不到位的地方请多多指教. Http 目前通用版本为 http 1.1 . Http连接大致分为2种常用的请求——GET,POS ...