Codeforces Round #413 B. T-shirt buying
来源:互联网 发布:战国红异端网络 编辑:程序博客网 时间:2024/06/01 09:06
A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers
m buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the j-th buyer we know his favorite color
A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won’t buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.
You are to compute the prices each buyer will pay for t-shirts.
题意
有 n 件T恤,每件正面与反面的颜色均为 1-3 中一种(可能相同),每件的价格为
解题思路
对颜色 1, 2, 3 分别建立优先队列,价格小的靠近队首。若每件衣服只属于一个队列,则对每个顾客抛出队首元素即可。但衣服具有正反两面,即每件衣服可能分属两个不同的优先队列,故为解决这种情况,应设置标记数组,记录该件衣服是否已经出售。
代码
#include<bits/stdc++.h>using namespace std;const int N = 200000 + 10;struct T_SHIRT { int p, a, b, id;} t[N], tmp;bool operator<(T_SHIRT a, T_SHIRT b) { return a.p > b.p;}bool mrk[N];priority_queue<T_SHIRT> que[4];int main(){ int n, m; scanf("%d", &n); for(int i=1;i<=n;i++) scanf("%d",&t[i].p); for(int i=1;i<=n;i++) scanf("%d",&t[i].a); for(int i=1;i<=n;i++) scanf("%d",&t[i].b); for(int i=1;i<=n;i++) { t[i].id = i; que[t[i].a].push(t[i]); if(t[i].a != t[i].b) que[t[i].b].push(t[i]); } scanf("%d",&m); for(int i=1, c;i<=m;i++) { scanf("%d",&c); if(que[c].empty()) printf("-1 "); while(!que[c].empty()) { tmp = que[c].top(); que[c].pop(); if(mrk[tmp.id]) { if(que[c].empty()) printf("-1 "); continue; } mrk[tmp.id] = 1; printf("%d ", tmp.p); break; } }}
- Codeforces Round #413 B. T-shirt buying
- Codeforces Round #413 B. T-shirt buying
- codeforces round #412 B. T-shirt buying
- Codeforces Round #413 Div. 1 + Div. 2 B. T-shirt buying
- Codeforces Round #413 (Div.1 + Div. 2) B. T-shirt buying
- codeforces Round #413 Div. 1 + Div. 2 B T-shirt buying
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) B. T-shirt buying
- CodeForces 799B (B) T-shirt buying
- codeforces #413 B T-shirt buying(set快速查找)
- Codeforces 799B T-shirt buying 题解
- codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B题B. T-shirt buying
- Codeforces Round #412 B. T-Shirt Hunt
- B. T-shirt buying(stl)
- Codeforces Round #412 B. T-Shirt Hunt (暴力枚举)
- T-shirt buying Codeforce 贪心
- 【Codeforces 807 B. T-Shirt Hunt】
- codeforces 412 B T-shirt Hunt
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) B. T-Shirt Hunt(模拟)
- Linux(Ubuntu)JDK安装
- 微信小程序之数据传递
- 第三方QQ登陆详解
- 04-NoSQL数据模型简介学习
- 单调栈
- Codeforces Round #413 B. T-shirt buying
- HTML5中CSS3的Transform属性
- 第七周 灵活布局
- Android中子线程真的不能更新UI吗?
- Codeforces Round #413 C. Fountains(RMQ线段树)
- 条件随机场CRF
- form表单的Enctype=multipart/form-data
- Linux系统安装时分区的选择
- 外观模式