最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

CodeforcesRound#268(Div.1)-B.TwoSets_html/css

来源:懂视网 责编:小采 时间:2020-11-27 15:55:33
文档

CodeforcesRound#268(Div.1)-B.TwoSets_html/css

CodeforcesRound#268(Div.1)-B.TwoSets_html/css_WEB-ITnose: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 satisfie
推荐度:
导读CodeforcesRound#268(Div.1)-B.TwoSets_html/css_WEB-ITnose: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 satisfie

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 #include #include #include using namespace std;const int M = 1e5 + 10;mapms;queuels;int ma[M];int main(){ int n,a,b; scanf("%d %d %d",&n,&a,&b); for(int i = 0; i < n; i++) { scanf("%d", ma + i); ms[ma[i]] = 1; } for(int i = 0; i < n; i++) if(!ms[a - ma[i]]) ls.push(ma[i]); while(!ls.empty()) { int u = ls.front(),tp; ls.pop(); if(ms[u] > 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 < n; i++) if(ms[ma[i]] == 1) printf("0 "); else printf("1 "); puts(""); return 0;}

    声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文档

    CodeforcesRound#268(Div.1)-B.TwoSets_html/css

    CodeforcesRound#268(Div.1)-B.TwoSets_html/css_WEB-ITnose: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 satisfie
    推荐度:
    标签: (1 Codeforces Two
    • 热门焦点

    最新推荐

    猜你喜欢

    热门推荐

    专题
    Top