Codeforces 268 B - Two Sets 搜索...

网友投稿 281 2022-09-14

Codeforces 268 B - Two Sets 搜索...

题意:

n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:

xbelongs to setA, then numbera-xmust also belong to setA.xbelongs to setB, then numberb-xmust also belong to setB.

Help Little X divide the numbers into two sets or determine that it's impossible.

Input

n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The next line contains n space-separated distinct integers p1, p2, ..., pn (1 ≤ pi ≤ 109).

Output

YES" in the first line. Then print n integers: b1, b2, ..., bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B.

NO" (without the quotes).

题解:

因为一个数要么A要么属于B..那么将它们都先定为A..再把不符合的调整到B..由于改变了一个位置从A到B..会让若干的数也会变..用一个dfs来处理就好...

Program:

#include#include#include#include #include#include#include#include#define MAXN 100005#define ll long long#define oo 1e+10#define eps 1e-10using namespace std; struct node{ int w,id; bool operator<(node a) const { return w1) { mid=r+l>>1; if (P[mid].w>x) r=mid; else l=mid; } if (P[l].w!=x) return 0; return l;}bool dfs(int x){ if (!x) return false; if (ans[P[x].id]) return true; ans[P[x].id]=1; if (find(a-P[x].w)) if (!dfs(find(a-P[x].w))) return false; if (!dfs(find(b-P[x].w))) return false; return true;}bool FindAns(){ int i; memset(ans,0,sizeof(ans)); for (i=1;i<=n;i++) { if (find(a-P[i].w)) continue; if (!dfs(i)) return false; } puts("YES"); for (i=1;i

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ZOJ 2587 - Unique Attack 最小割,判断割边集是否唯一
下一篇:私域流量的留存和极速裂变秘诀!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~