【题目链接】:http://codeforces.com/contest/799/problem/B

【题意】



告诉你每个人喜欢的衣服的颜色;

然后告诉你每件衣服的正面和背面的颜色以及它的价格;

只要某件衣服的正面或背面是某个人喜欢的颜色;

则那个人就会喜欢它;

然后每个人会挑自己最喜欢的且最便宜的衣服买;

给你每个人来的先后顺序;

让你求出每个人买的衣服的价格;

【题解】



定义3个set;

每次取出对应的set的头节点;

然后把那件衣服另外一面的颜色,在另外一个set中删去;

(或者,先不删去,记录某件衣服有没有被买去,然后每次取头结点,知道遇到一件没有被买去的衣服为止)



【Number Of WA】



0



【完整代码】

code 1

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5+100; struct rec{
LL p,id;
friend bool operator < (rec a,rec b)
{
return a.p<b.p||(a.p==b.p && a.id<b.id);
}
}; set <rec> myset[4];
int n,p[N],a[N],b[N]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n;
rep1(i,1,n)
cin>>p[i];
rep1(i,1,n)
cin >>a[i];
rep1(i,1,n)
cin >>b[i];
rep1(i,1,n)
{
myset[a[i]].insert(rec{p[i],i});
if (a[i]!=b[i])
myset[b[i]].insert(rec{p[i],i});
}
cin >> n;
rep1(i,1,n)
{
int x;
cin >>x;
if (myset[x].empty())
cout<<-1<<endl;
else
{
__typeof(myset[x].begin()) c=myset[x].begin();
rec tou = (*c);
cout << tou.p;
myset[x].erase(c);
//cout <<x<<' '<<(x^a[tou.id]^b[tou.id])<<endl;
//cout <<tou.p<<endl;
if (a[tou.id]!=b[tou.id])
{
int t = (x^a[tou.id]^b[tou.id]);
c = myset[t].lower_bound(rec{p[tou.id],tou.id});
myset[t].erase(c);
}
}
if (i==n) cout << endl;
else
cout<<' ';
}
//init??????
return 0;
}

code 2

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5+100; struct rec{
LL p,id;
friend bool operator < (rec a,rec b)
{
return a.p<b.p||(a.p==b.p && a.id<b.id);
}
}; set <rec> myset[4];
int n,p[N],a[N],b[N];
bool vis[N]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n;
rep1(i,1,n)
cin>>p[i];
rep1(i,1,n)
cin >>a[i];
rep1(i,1,n)
cin >>b[i];
rep1(i,1,n)
{
myset[a[i]].insert(rec{p[i],i});
myset[b[i]].insert(rec{p[i],i});
}
cin >> n;
rep1(i,1,n)
{
int x;
cin >>x;
bool fi = false;
while (!myset[x].empty())
{
auto y = myset[x].begin();
rec tou = *y;
myset[x].erase(y);
if (vis[tou.id]) continue;
vis[tou.id] = true;
fi = true;
cout << tou.p <<' ';
break;
}
if (!fi)
cout <<-1<<' ';
}
//init??????
return 0;
}

【codeforces 799B】T-shirt buying的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 796A】Buying A House

    [题目链接]:http://codeforces.com/contest/796/problem/A [题意] 让你选一个最靠近女票的,且能买的房子; 输出你和你女票的距离; [题解] 枚举 [Num ...

  3. 【15.07%】【codeforces 625A】Guest From the Past

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  4. 【codeforces 762B】USB vs. PS/2

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. mysql稳定的版本号选择及下载说明(2014-11-10)

    怎样选择新稳定的版本号       mysql的版本号大概能够分为Alpha.Beta.GA. GA版即mysql官方公布的稳定版本号. 怎样在官方下载Mysql        能够通过http:// ...

  2. ubuntu14.04上搭建android开发环境

    这几天心血来潮,想在ubuntu上写写android软件.所以就上网找些资料在ubuntu上搭建android环境.结果要么时不完整的,要么就是过时的. 所以我把我搭建android环境的过程写下了, ...

  3. 解决TortoiseGit下载代码每次要输入用户名、密码

    解决办法: 方案1: 右键>ortoiseGit → Settings → Git → Credential 设置为 wincred - this repository only 或者 winc ...

  4. Unity3D 射线指定层获取GameObject 注意 LayerMask

    这一篇是纯技术讨论,看过我前面文章的童鞋应该清楚,我的奔跑是靠鼠标响应的,鼠标点到哪就跑到哪,后来又有了界面,麻烦就来了,我的界面居然能点 穿.我不希望点界面的时候还能点到界面后面的地面上,角色傻不拉 ...

  5. ScrollViewer滚动究竟来触发载入数据的Behavior

    近期项目中遇到载入数据的性能问题, 原因是.net4.0的虚拟化支持不够完毕,有好多bug在4.5才修复. 我们仅仅能利用大家通用的做法来延迟载入数据: 每次载入固定少量的数据.当拖动究竟后.继续载入 ...

  6. etcd创建集群并增加节点

    下载安装 从这下载https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz tar ...

  7. [JavaEE] IBM - Spring 系列: Spring 框架简介

    Spring AOP 和 IOC 容器入门 在这由三部分组成的介绍 Spring 框架的系列文章的第一期中,将开始学习如何用 Spring 技术构建轻量级的.强壮的 J2EE 应用程序.develop ...

  8. C - Twins(贪心)

    Problem description Imagine that you have a twin brother or sister. Having another person that looks ...

  9. ADODB.RecordSet常用方法查询

    rs = Server.CreateObject("ADODB.RecordSet") rs.Open(sqlStr,conn,1,A) 注:A=1表示读取数据:A=3表示新增.修 ...

  10. date 格式化

    以这个为例:    yyyy-MM-dd HH:mm:ss 首先得写好你需要的模板 options.sign = options.sign || 'yyyy-MM-dd HH:mm:ss'; 其次就可 ...