CF799B T-shirt buying
题目大意
有一些衣服,它们有价格、正面的颜色和反面的颜色。现有一群顾客按顺序来买存在某颜色且价格最低的衣服(不存在则不会买),求每个顾客花了多少钱。
思路

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std; const int MAX_OBJ = 200010, MAX_COLOR = 5;
int TotObj; struct Obj
{
int Price, A, B;
bool Vis;
}_objs[MAX_OBJ]; struct Cmp
{
bool operator () (Obj *a, Obj *b)
{
return a->Price > b->Price;
}
}; priority_queue<Obj*, vector<Obj*>, Cmp> q[3][MAX_COLOR]; int main()
{
scanf("%d", &TotObj);
for (int i = 1; i <= TotObj; i++)
scanf("%d", &_objs[i].Price);
for (int i = 1; i <= TotObj; i++)
{
scanf("%d", &_objs[i].A);
q[1][_objs[i].A].push(_objs + i);
}
for (int i = 1; i <= TotObj; i++)
{
scanf("%d", &_objs[i].B);
q[2][_objs[i].B].push(_objs + i);
}
int opCnt;
scanf("%d", &opCnt);
while(opCnt--)
{
int color;
scanf("%d", &color); while(!q[1][color].empty() && q[1][color].top()->Vis)
q[1][color].pop();
Obj *obj1 = q[1][color].empty() ? NULL : q[1][color].top();
while(!q[2][color].empty() && q[2][color].top()->Vis)
q[2][color].pop();
Obj *obj2 = q[2][color].empty() ? NULL : q[2][color].top(); Obj *ans = obj1 && obj2 ? (obj1->Price < obj2->Price ? obj1 : obj2) : obj1 ? obj1 : obj2;
bool Is1 = obj1 && obj2 ? (obj1->Price < obj2->Price) : (obj1 != NULL);
if (!ans)
printf("-1 ");
else
{
printf("%d ", ans->Price);
ans->Vis = true;
q[Is1 ? 1 : 2][Is1 ? ans->A : ans->B].pop();
}
}
return 0;
}
CF799B T-shirt buying的更多相关文章
- 【CF799B】T-shirt buying(一道很水的小根堆)
点此看题面 大致题意: 有\(n\)件T恤衫,告诉你每件T恤衫的价格以及它正面和反面的颜色(\(1≤\)颜色的编号\(≤3\)),现在有m个顾客,已知每个人想要的衣服的颜色(一件T恤衫只要有一面的颜色 ...
- ACM BUYING FEED
BUYING FEED 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 Farmer John needs to travel to town to pick up ...
- [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草
[BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草 试题描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草. 他知道N(1≤N≤100)个干草 ...
- uva 10626 - Buying Coke(记忆化搜索)
题目链接:10626 - Buying Coke 题目大意:给出要买可乐的数量, 以及1元,5元和10元硬币的数量, 每瓶可乐8元,每次照钱会按照最少硬币的方式找回, 问如何投币可使得投入的硬币数最少 ...
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草( dp )
无限背包dp.. 因为题目中说至少到 H 磅 , 我就直接把 H * 2 了.. ----------------------------------------------------------- ...
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草
题目 1618: [Usaco2008 Nov]Buying Hay 购买干草 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 679 Solved: ...
- 2020: [Usaco2010 Jan]Buying Feed, II
2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 220 Solved: 162[ ...
- 新概念英语(1-11)Is this your shirt ?
Is this your shirt?Whose shirt is white? A:Whose shirt is that? Is this your shirt, Dave? Dave:No si ...
- Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口”
Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口” Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directo ...
随机推荐
- CentOS7将firewall切换为iptables防火墙
- Codeforces_733D
D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- unittest 是什么?怎么用?
unittest单元测试框架详解 https://www.cnblogs.com/fighter007/p/8245063.html unittest最详细的解说 https://www.cnblog ...
- ES6 作用域的问题
- Java并发——阿里架构师是如何巧用线程池的!
一.创建线程 1.创建普通对象,只是在JVM的堆里分配一块内存而已 2.创建线程,需要调用操作系统内核的API,然后操作系统需要为线程分配一系列资源,成本很高 线程是一个重量级对象,应该避免频繁创建和 ...
- 零基础学习Linux培训,应该选择哪个培训班?
云计算早已不是什么稀奇的概念,它的火爆让Linux运维工程师这个职业越来越重要.在当今各类云平台提供的系统中,Linux系统几乎毫无争议的独占鳌头,市场份额进一步扩张. 这也让Linux运维工程师职位 ...
- The C++ Programming Language - Bjarne Stroustrup
Preface Part 1: Introduction 1.1 The Structure of This Book 1.1.1 Introduction 1.1.2 Basic Facilitie ...
- git 的简单使用(3)
Git鼓励大量使用分支: 查看分支:git branch 创建分支:git branch <name> 切换分支:git checkout <name> 创建+切换分支:git ...
- pyhton 网络爬取软考题库保存text
#-*-coding:utf-8-*-#参考文档#https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#find-al ...
- navicate远程访问ubuntu上的mysql数据库
安装mysql 首先检查系统中是否已经安装了MySQL,在终端里面输入: sudo netstat -tap | grep mysql 如上所示就是正确安装并启动,启动命令为 sudo /etc/in ...