Codeforces 468 B Two Sets
题意:就是将一对数放进setA, setB中, 如果放进setA的话要求满足 x与a-x都在这个集合里面, 如果放进setB中要求满足x与b-x都在这个集合中。
题解:我们将能放进B的元素优先放在B中,如果能放进B就直接将2个元素放进B中。 然后如果能放进A中就放进A中, 如果在放入A过程中发现对应元素在setB中,那么就找对应元素的对应元素能不能放进A中。如果在元素放入B的过程中发现对应元素在A中,那么就无解了,因为优先放B中。
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
typedef pair<int,int> pll;
const int N = 1e5+;
int vis[N], pi[N];
map<int, int> m;
int n, a, b;
bool dfs(int v, int c){
if(c == ){
if(vis[m[b-v]] == -){
vis[m[b-v]] = vis[m[v]] = ;
return true;
}
if(vis[m[a-v]] == -){
vis[m[a-v]] = vis[m[v]] = ;
return true;
}
if(vis[m[a-v]] == ){
vis[m[a-v]] = vis[m[v]] = ;
return dfs(b-a+v,);
}
return false;
}
else if(c == ){
if(vis[m[a-v]] == - || vis[m[a-v]] == ){
vis[m[a-v]] = vis[m[v]] = ;
return true;
}
if(vis[m[a-v]] == ){
vis[m[a-v]] = vis[m[v]] = ;
return dfs(b-a+v,);
}
return false;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> n >> a >> b;
vis[] = ;
for(int i = ; i <= n; i++){
vis[i] = -;
cin >> pi[i];
m[pi[i]] = i;
}
for(int i = ; i <= n; i++){
if(vis[i] == -){
if(dfs(pi[i],)) ;
else {
cout << "NO\n";
return ;
}
}
}
cout << "YES\n";
for(int i = ; i < n; i++)
cout << vis[i] << ' ';
cout << vis[n] << endl;
return ;
}
Codeforces 468 B Two Sets的更多相关文章
- codeforces B. Eight Point Sets 解题报告
题目链接:http://codeforces.com/problemset/problem/334/B 一开始看到题目,有点怯,理解了题目后,其实并不难.这句话是突破口 three distinct ...
- Codeforces 486D D. Valid Sets
http://codeforces.com/contest/486/problem/D 题意:给定一棵树,点上有权值,以及d,要求有多少种联通块满足最大值减最小值小于等于d. 思路:枚举i作为最大的点 ...
- Codeforces 425E Sereja and Sets dp
Sereja and Sets 我们先考虑对于一堆线段我们怎么求最大的不相交的线段数量. 我们先按 r 排序, 然后能选就选. 所以我们能想到我们用$dp[ i ][ j ]$表示已经选了 i 个线段 ...
- 【codeforces 103E】 Buying Sets
http://codeforces.com/problemset/problem/103/E (题目链接) 题意 给出$n$个数,每个数与一个集合相关联.从其中选出最小的若干个数,选出的数的个数与这些 ...
- Codeforces 469 D. Two Sets (并查集)
题目链接:Two Sets 题意: 有n个数,要分成A.B两组,要求如果x∈A则a-x∈A,如果x∈B则b-x∈B,问是否存在一种符合要求的分法. 题解: 并查集,先增加两个点表示A和B集合的根,对于 ...
- 【53.57%】【codeforces 722D】Generating Sets
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 1042 F Leaf Sets 贪心
Leaf Sets 题意:给你一棵树,树上有n个点,只有一条边的点叫做叶子,现在要求把所有的叶子分组,每个组内的所有叶子的距离都不能大于k. 题解: 我们可以随意找一个不是叶子的节点当做这颗树的根节点 ...
- codeforces 486 D. Valid Sets(树形dp)
题目链接:http://codeforces.com/contest/486/problem/D 题意:给出n个点,还有n-1条边的信息,问这些点共能构成几棵满足要求的树,构成树的条件是. 1)首先这 ...
- codeforces 334B - Eight Point Sets
题意难懂,其实就是x1<x2<x3与y1<y2<y3两两组合成九个点,去掉(x2,y2),剩余八个.这样的八个点才是满足要求的. 忘去重了 #include<cstdio ...
随机推荐
- CoreCLR Host源码分析(C++)
废话不多说,直接上源码: 1.在托管程序集里面执行方法 HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId,//通过CreateAppDomai ...
- 使用hexo中遇到的问题
- Something wrong with EnCase v8 index search results
My friend told me that she installed EnCase v8.05 on her workstation which OS version is Win 10. She ...
- go杂货铺
json序列化 内存中变成可存储或传输的过程称之为序列化(dict,split,struct转string) package main import ( "encoding/json&quo ...
- Kafka学习(四)-------- Kafka核心之Producer
通过https://www.cnblogs.com/tree1123/p/11243668.html 已经对consumer有了一定的了解.producer比consumer要简单一些. 一.旧版本p ...
- 旁友数独会伐啦?python秒解数独了解下伐啦?
前几天和隔壁邻居玩斗地主被发现了,牌被没收了,斗地主是斗不了了,但我还想和邻居玩耍.如果你还想斗斗地主,戳:趁老王不在,和隔壁邻居斗斗地主,比比大小 想破脑袋终于让我想到一个游戏,数独!什么叫数独?数 ...
- Unity基础之:UnityAPI的学习
版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...
- The introduction of the book American daily English notes (enlarged edition)
After reading the book of American daily English notes written by Linkun Yang[1], I think I should a ...
- android ——ListView
谷歌官方文档的介绍:https://developer.android.com/reference/android/widget/ListView.html 显示可垂直滚动的视图集合,其中每个视图都立 ...
- 创建docker容器遇到的错误
1.问题截图 2.问题描述 出现该问题就是docker版本和系统版本不兼容导致的. 现在的系统版本和docker的版本如下: 3.问题解决 安装低版本的docker或者高版本的系统(Centos7.4 ...