Codeforces Round #268 (Div. 1)-B. Two Sets_html/css_WEB-ITnose
time limit per test 1 second
memory limit per test 256 megabytes
Little X has 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:
Help Little X divide the numbers into two sets or determine that it's impossible.
Input
The first line contains three space-separated integers 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
If there is a way to divide the numbers into two sets, then print "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.
If it's impossible, print "NO" (without the quotes).
Sample test(s)
Input
4 5 92 3 4 5
Output
YES0 0 1 1
Input
3 3 41 2 4
Output
NO
Note
It's OK if all the numbers are in the same set, and the other one is empty.
意解:这道题有很多的解法,我是用BFS做的,但是比赛因为一点小错误fail system text. 我把a - x 不存在的暂时确定为b
集合,存进队列,然后BFS,但是要注意一个问题,但当前的数配对的数是a集合里面的话,我们就要把a集合里面的那
个数取到b集合,如果没发取的,则输出"NO",详细看代码吧!
AC代码:
#include#include #include #include
上一篇: ps实现放大图片保持清晰度
推荐阅读
-
Codeforces Round #272 (Div. 1)D(字符串DP)_html/css_WEB-ITnose
-
Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)_html/css_WEB-ITnose
-
Codeforces Round #258 (Div. 2) B. Jzzhu and Sequences(矩阵快速幂)_html/css_WEB-ITnose
-
Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences_html/css_WEB-ITnose
-
Codeforces Round #280 (Div. 2)-B. Vanya and *s_html/css_WEB-ITnose
-
Codeforces Round #275 (Div. 1)C(状压+期望)_html/css_WEB-ITnose
-
Codeforces Round #276 (Div. 1)B(暴力)_html/css_WEB-ITnose
-
Codeforces Round #FF (Div. 1)-A,B,C_html/css_WEB-ITnose
-
Codeforces Round #250 (Div. 1)B(排序+并查集)_html/css_WEB-ITnose
-
Codeforces Round #673 (Div. 2) B. Two Arrays(思维,构造)