B. Two Sets

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/468/problem/B

Description

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 Input

  1. 4 5 9
    2 3 4 5

Sample Output

  1. YES
    0 0 1 1

HINT

题意

给你n个数,再给你俩集合,表示如果x在集合A里面的话,那么a-x也得在集合A

集合B同理

问你是否能够构造出来

题解:

直接暴力找就好了,如果能扔进A就扔进去,否则就扔B里面,就暴力

代码:

  1. //qscqesze
  2. #pragma comment(linker, "/STACK:1024000000,1024000000")
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <ctime>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <set>
  10. #include <bitset>
  11. #include <vector>
  12. #include <sstream>
  13. #include <queue>
  14. #include <typeinfo>
  15. #include <fstream>
  16. #include <map>
  17. #include <stack>
  18. typedef long long ll;
  19. using namespace std;
  20. //freopen("D.in","r",stdin);
  21. //freopen("D.out","w",stdout);
  22. #define sspeed ios_base::ssecondnc_with_stdio(0);cin.tie(0)
  23. #define maxn 100006
  24. #define mod 1000000007
  25. #define eps 1e-9
  26. #define PI acos(-1)
  27. const double EP = 1E- ;
  28. int Num;
  29. //const int inf=0first7fffffff;
  30. const ll inf=;
  31. inline ll read()
  32. {
  33. ll x=,f=;char ch=getchar();
  34. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  35. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  36. return x*f;
  37. }
  38. //*************************************************************************************
  39.  
  40. map<int,int> A,B;
  41. queue<int> q;
  42. vector<int>p;
  43.  
  44. int main()
  45. {
  46. int n=read(),a=read(),b=read();
  47. for(int i=;i<n;i++)
  48. {
  49. int x=read();p.push_back(x);
  50. A[x]++;
  51. }
  52. for(int i=;i<n;i++)
  53. {
  54. if(A[p[i]]>&&A[a-p[i]]==)
  55. q.push(p[i]);
  56. }
  57. while(!q.empty())
  58. {
  59. int now = q.front();
  60. q.pop();
  61. if(A[now]>&&A[a-now]==&&A[b-now]==)
  62. {
  63. cout<<"NO"<<endl;
  64. return ;
  65. }
  66. --A[now];
  67. --A[b-now];
  68. ++B[now];
  69. ++B[b-now];
  70. if(A[b-now]==&&A[a-b+now]>)
  71. q.push(a-b+now);
  72. }
  73. cout<<"YES"<<endl;
  74. for(int i=;i<n;i++)
  75. if(A[p[i]]>)
  76. cout<<"0 ",--A[p[i]];
  77. else
  78. cout<<"1 ";
  79. }

Codeforces Round #268 (Div. 1) B. Two Sets 暴力的更多相关文章

  1. Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]

    8161957                 2014-10-10 06:12:37     njczy2010     D - Two Sets             GNU C++     A ...

  2. Codeforces Round #277 (Div. 2) D. Valid Sets 暴力

    D. Valid Sets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem ...

  3. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  4. Codeforces Round #268 (Div. 1) A. 24 Game 构造

    A. 24 Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/A D ...

  5. 贪心+bfs 或者 并查集 Codeforces Round #268 (Div. 2) D

    http://codeforces.com/contest/469/problem/D 题目大意: 给你一个长度为n数组,给你两个集合A.B,再给你两个数字a和b.A集合中的每一个数字x都也能在a集合 ...

  6. Codeforces Round #277 (Div. 2) D. Valid Sets (DP DFS 思维)

    D. Valid Sets time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #268 (Div. 2) (被屠记)

    c被fst了................ 然后掉到600+.... 然后...估计得绿名了.. sad A.I Wanna Be the Guy 题意:让你判断1-n个数哪个数没有出现.. sb题 ...

  8. Codeforces Round #277 (Div. 2) D. Valid Sets DP

    D. Valid Sets   As you know, an undirected connected graph with n nodes and n - 1 edges is called a  ...

  9. Codeforces Round #268 (Div. 2)

    补题解: E:只会第四种解法:也只看懂了这一种. PS:F[X+10^18]=F[X]+1;F[X]表示X的数字之和; 假设X,F[10^18+X]+F[10^18+X-1]+......F[10^1 ...

随机推荐

  1. Android-xUtils框架介绍(二)

    昨天对xUtils整体上做了一个简单的介绍,今天咱们就代码码起,真刀实枪的也看看,看看如何快速便捷的把xUtils给集成到大家的项目中去.xUtils中有四大组件可以供我们使用,分别是ViewUtil ...

  2. CSS那些事儿-阅读随笔3(清除浮动)

    浮动主要是由浮动(float)属性导致的页面错位现象,清除浮动不仅能解决页面错位的现象,还可以解决子元素浮动导致父元素背景无法自适应子元素高度的问题.在CSS样式中,主要利用clear属性中的both ...

  3. javascript 一些需要知道的东西

    这里我直接贴出代码,注释已经补全,欢迎指正: <script type="text/javascript"> /** 1,js中一切皆是对象,函数也是, 2,当定义变量 ...

  4. 【Struts】strust.xml中<result type="">所有类型详解

    在默认时,<result>标签的type属性值是“dispatcher”(实际上就是转发,forward).开发人员可以根据自己的需要指定不同的类型,如redirect.stream等.如 ...

  5. SharePoint 2010 获取列表中所有数据(包括文件夹内)的方法

    转: http://blog.csdn.net/wangwenism/article/details/8751411 SharePoint的列表能存储文件以及文件夹,用户使用的时候,经常会建几个分类文 ...

  6. Gen_server行为分析与实践

    1.简介 Gen_server实现了通用服务器client_server原理,几个不同的客户端去分享服务端管理的资源(如图),gen_server提供标准的接口函数和包含追踪功能以及错误报告来实现通用 ...

  7. jvm常量池 vsv为什么1000 == 1000返回为False,而100 == 100会返回为True?

    在jvm规范中,每个类型都有自己的常量池.常量池是某类型所用常量的一个有序集合,包括直接常量(基本类型,String)和对其他类型.字段.方法的符号引用.之所以是符号引用而不是像c语言那样,编译时直接 ...

  8. VS2010 Chromium编译

    推荐使用Windows 7及以后系统,最少8G内存,预留出50G磁盘空间 搭建Visual Studio 2010开发环境 1.安装Visual Studio 2010专业版或者旗舰版 2.安装VS2 ...

  9. Webservice、WSDL三种服务访问的方式【转】

    http://www.cnblogs.com/yongfeng/archive/2013/01/30/2883146.html 用soapUI试了下wsdl的测试,但还是不知道webService和W ...

  10. SDUT 3258 Square Number 简单数学

    和上一题一样,把平方因子除去,然后对应的数就变成固定的 #include <cstdio> #include <iostream> #include <algorithm ...