B. T-shirt buying(stl)
来源:互联网 发布:电商系统源码下载 编辑:程序博客网 时间:2024/06/05 22:39
题目描述:
有一个整数n表示有n种衬衫(每种衬衫只有一件),然后输入这n件衬衫的价格,然后依次输入每一件衬衫前面的颜色,再依次输入每一件衬衫后面的颜色(所有的颜色都是用1,2,3表示的),然后输入m表示有m个人,然后输入这m个人喜欢的颜色,每个人买一件衣服,一个人要买这件衣服,必须前后两面至少有一面是他喜欢的颜色,如果同时有多件选择最低价格那一件,当然,选完这件之后其他人就不能再选这件了,如果没有符合条件的就输出-1,否则输出这件衬衫的价格;
输入:
5300 200 400 500 9111 2 1 2 32 1 3 2 162 3 1 2 1 1输出:
200 400 300 500 911 -1
一看就很容易超时,然后怎么做呢,最好选择set吧,我个人感觉它应该比较快,好像是堆排序对吧,然后必须要开一个数组标记是否用过,set里插入的话因为价值是不同的,所以要插入价值和标号,插入的set要有三个分别为颜色代表,然后表输出边删除;
代码如下:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200000+10;
set< pair<int,int> >s[4];
int p[maxn],a[maxn],b[maxn],vis[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&p[i]);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
for(int i=0;i<n;i++) scanf("%d",&b[i]);
for(int i=0;i<n;i++)
{
s[a[i]].insert(make_pair(p[i],i));
s[b[i]].insert(make_pair(p[i],i));
}
int m;
scanf("%d",&m);
int c;
for(int i=0;i<m;i++)
{
int ans=-1;
scanf("%d",&c);
if(i!=0) printf(" ");
while(!s[c].empty())
{
int x=(*(s[c].begin())).second;
s[c].erase(s[c].begin());
if(vis[x]) continue;
vis[x]=1;
ans=p[x];
break;
}
printf("%d",ans);
}
return 0;
}
- B. T-shirt buying(stl)
- CodeForces 799B (B) T-shirt buying
- codeforces round #412 B. T-shirt buying
- Codeforces 799B T-shirt buying 题解
- Codeforces Round #413 B. T-shirt buying
- Codeforces Round #413 B. T-shirt buying
- codeforces #413 B T-shirt buying(set快速查找)
- T-shirt buying Codeforce 贪心
- 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
- B. T-Shirt Hunt
- codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B题B. T-shirt buying
- Codeforces807 B. T-Shirt Hunt
- 807B T-Shirt Hunt
- Codeforces Round #412 B. T-Shirt Hunt (暴力枚举)
- CF#807 B. T-Shirt Hunt(水题)
- 单位转换
- 51学习库(2)--矩阵键盘
- 设计模式
- (复习)Struts2+MySQL完成登录数据是够为空的校验(二)
- 反射机制调用普通成员方法
- B. T-shirt buying(stl)
- 非递减排列 非递增排列 递减排列 递增排列
- java XML转JSON格式
- flex 最后一行左对齐
- 线程 中断 Thread.interrupt()使用
- HTML5学习笔记 —— JavaScript语句
- 如何优化MySQL
- [Leetcode] 135. Candy
- 微信小程序获取用户openid