【codeforces 799B】T-shirt buying
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 796A】Buying A House
[题目链接]:http://codeforces.com/contest/796/problem/A [题意] 让你选一个最靠近女票的,且能买的房子; 输出你和你女票的距离; [题解] 枚举 [Num ...
- 【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 ...
- 【codeforces 762B】USB vs. PS/2
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- java 线程 错失的信号、notify() 与notifyAll的使用
package org.rui.thread.block; import java.util.Timer; import java.util.TimerTask; import java.util.c ...
- Service启动模式
Service简单介绍 Service表示服务.是Android系统的核心组件之中的一个. Service的本质是一个继承了android.app.Service的java类: ...
- 什么是Spark?
什么是Spark Spark是一个基于内存计算的开源的集群计算系统,目的是让数据分析更加高速.Spark很小巧玲珑,由加州伯克利大学AMP实验室的Matei为主的小团队所开发. 使用的语言是Scala ...
- 【NOIP 2002】 字串变换
[题目链接] https://www.luogu.org/problemnew/show/P1032 [算法] 广度优先搜索 用stl库里的map来判重 [代码] #include<bits/s ...
- Juniper交换机维护
Juniper交换机维护操作之一: 1.1 交换机启动和关闭 1.1.1 重新启动 1. 使用具有足够权限的用户名和密码登陆CLI命令行界面. 2. 在提示符下输入下面的命令: use ...
- Python 3.x 判断 dict 是否包含某个键
Python 3.x不再支持 has_key() 函数,而被__contains__('key')所替代,会返回bool,可以用其做判断. 代码示例: >>> user = 'dad ...
- 关于Html基础语法学习
晚上做完初赛,好像有点颓,就来学了学html,毕竟博客里面会用到嘛. 首先贴出我所学习的教程 http://www.w3school.com.cn/html/index.asp 我觉得吧,可能以我的记 ...
- showdialog
在C#中窗口的显示有两种方式:模态显示(showdialog)和非模态显示(show). 区别: 模态与非模态窗体的主要区别是窗体显示的时候是否可以操作其他窗体.模态窗体不允许操作其他窗体,非模态窗体 ...
- 使用vs2017创建项目并添加到git中
参考 https://blog.csdn.net/qq373591361/article/details/71194651 https://blog.csdn.net/boonya/article/d ...
- DevExpress 如何读取当前目录下文件,加载至grid
DBFileName=DevExpress.Utils.FileHelper.FindingFileName(Appliaction.StartupPath,"Data\\Product&g ...