>웹 프론트엔드 >HTML 튜토리얼 >Codeforces Round #268 (Div. 1)-B. Two Sets_html/css_WEB-ITnose

Codeforces Round #268 (Div. 1)-B. Two Sets_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-24 11:57:221257검색

  B. Two Sets

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:

  • If number x belongs to set A, then number a?-?x must also belong to set A.
  • If number x belongs to set B, then number b?-?x must also belong to set B.
  • 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 <iostream>#include <cstdio>#include <queue>#include <map>using namespace std;const int M = 1e5 + 10;map<int>ms;queue<int>ls;int ma[M];int main(){    int n,a,b;    scanf("%d %d %d",&n,&a,&b);    for(int i = 0; i  0 && ms[a - u] == 0 && ms[b - u] == 0)        {            puts("NO");            return 0;        }        --ms[u]; //表示已被取到b集合去了;        --ms[b - u];        tp = a - b + u;        if(ms[tp]) ls.push(tp);  //如果我所取的那个数是a集合里的,在bfs把另一个数取出来.    }    puts("YES");    for(int i = 0; i       <br>      <br>      <p></p>               </int></int></map></queue></cstdio></iostream>
    성명:
    본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.