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 ...
随机推荐
- 简单的KKL诊断线~~~自己在家都可以制作obd诊断接口了 ~~
简单的KKL诊断线~~~自己在家都可以制作~~ 适合bmw 07年以前的车型,因为新的车型使用D-can作为诊断接口,所以不能再使用kkl诊断接口不过SB开头的宝马3系还是可以使用的 更多内容欢迎查看 ...
- Linux Shell 小知识
${} ——变量替换 通常 $var 与 ${var} 没有区别,但是用 ${} 会比较精确的界定变量名称的范围. name='Ace' echo "result1: my name is ...
- (转)Hibernate快速入门
http://blog.csdn.net/yerenyuan_pku/article/details/64209343 Hibernate框架介绍 什么是Hibernate 我们可以从度娘上摘抄这样有 ...
- iOS错误报告中关于崩溃地址的分析
http://blog.csdn.net/gaoyp/article/details/46912753 一.错误报告中的三种地址:stack addressload addresssymbol add ...
- 思维风暴 codeforces (1060A) Phone Numbers
这个题我真是我的问题,我看到这种题直接就想着怎么用string去枚举破解,开了一个数组去做结果模拟失败,可能开个stl容器能做的好一点...但是这个题完全不是这样做的...实际上直接比较8的个数和合法 ...
- php观察折模式
<?php class Paper{ private $_observers = array(); public function register($sub){ $this->_obse ...
- Linux常用shell命令持续总结
1. 查看端口运行 netstat -lnp|grep 80 2. 定时任务 Crontab -e 编辑任务 Crontab -l 查看当前任务列表 /var/log/cron-* 任务日志
- 00.Python中下划线的5种含义
转自这里 先放上 简短的"速查表",罗列了五种Python下划线模式的含义: 模式 举例 含义 单前导下划线 _var 命名约定,仅供内部使用.通常不会由Python解释器强行执行 ...
- 49.ardinality算法之优化内存开销以及HLL算法
主要知识点 precision_threshold参数的理解 HLL算法优化(hash) cardinality,count(distinct),5%的错误率,性能在100ms左右 ...
- hdu 5175 Misaki's Kiss again
Misaki's Kiss again Accepts: 75 Submissions: 593 Time Limit: 2000/1000 MS (Java/Others) Memory L ...