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 ...
随机推荐
- Laravel (5.5.33) 加载过程(二)
本次说明代码 /* |-------------------------------------------------------------------------- | Turn On The ...
- swift单例创建的几种方法
//单例方法1 class SingleTonOne{ static var sharedInstanceOne:SingleTonOne{ struct SingleTonStruct { stat ...
- Ruby开发环境的搭建
1.Ruby的下载 https://rubyinstaller.org/downloads/ 2.Ruby的安装 3.Eclipse配置Ruby开发环境 插件地址:http://rubyeclipse ...
- (转)Hibernate的一级缓存
http://blog.csdn.net/yerenyuan_pku/article/details/70148567 Hibernate的一级缓存 Hibernate的一级缓存就是指Session缓 ...
- Django的文件下载
在实际的项目中很多时候需要用到下载功能,如导excel.pdf或者文件下载,当然你可以使用web服务自己搭建可以用于下载的资源服务器,如nginx,这里我们主要介绍django中的文件下载. 我们这里 ...
- xcode构建webdriverAgent时报错Messaging unqualified id的解决办法
在使用xcode构建webdriverAgent时,提示build failed,报错信息为:semantic issue:Messaging unqualified id,可以参考以下解决方案 xc ...
- MVC Ajax调用Action时-OnActionExecuting RedirectResult 无法跳转的处理办法
public class BaseController : Controller { protected override void OnActionExecuting(ActionExecuting ...
- HDU 3152 Obstacle Course(优先队列,广搜)
题目 用优先队列优化普通的广搜就可以过了. #include<stdio.h> #include<string.h> #include<algorithm> usi ...
- postgres主从配置
运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) 开始部署postgres主从(如果没不会安装postgres的请去上一个博文中查看) 这里我使用了两台服务器部署 主:192.168 ...
- 【模板】Link-Cut Tree
#include<cstdio> #include<algorithm> #define N 500010 #define rg register #define ls (c[ ...