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

4 5 9
2 3 4 5

Sample Output

YES
0 0 1 1

HINT

题意

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

集合B同理

问你是否能够构造出来

题解:

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

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::ssecondnc_with_stdio(0);cin.tie(0)
#define maxn 100006
#define mod 1000000007
#define eps 1e-9
#define PI acos(-1)
const double EP = 1E- ;
int Num;
//const int inf=0first7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* map<int,int> A,B;
queue<int> q;
vector<int>p; int main()
{
int n=read(),a=read(),b=read();
for(int i=;i<n;i++)
{
int x=read();p.push_back(x);
A[x]++;
}
for(int i=;i<n;i++)
{
if(A[p[i]]>&&A[a-p[i]]==)
q.push(p[i]);
}
while(!q.empty())
{
int now = q.front();
q.pop();
if(A[now]>&&A[a-now]==&&A[b-now]==)
{
cout<<"NO"<<endl;
return ;
}
--A[now];
--A[b-now];
++B[now];
++B[b-now];
if(A[b-now]==&&A[a-b+now]>)
q.push(a-b+now);
}
cout<<"YES"<<endl;
for(int i=;i<n;i++)
if(A[p[i]]>)
cout<<"0 ",--A[p[i]];
else
cout<<"1 ";
}

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. 谈谈javascript插件的写法

    插件顾名思义就是能在一个页面多处使用, 各自按自己的参数配置运行, 并且相互不会冲突. 会写javascript插件是进阶js高级的必经之路, 也是自己所学知识的一个典型的综合运用. 如果你还没头绪, ...

  2. CSS那些事儿-阅读随笔2(选择符的组合与优先级/权重)

    在知道了CSS选择符最基础的知识后,就要综合利用它们了.这里就记录几种常见的用法. 1.针对性的使用类选择符或者ID选择符 类选择符在一个页面中可能会在不同的地方应用,那么就需要有针对性地使用类选择符 ...

  3. java参数传递时到底是值传递还是引用传递

    java参数传递时到底是值传递还是引用传递(baidu搜集) 问”,很多人的BLOG里都引用这些面试题,最近因为工作内容比较枯燥,也来看看这些试题以调节一下口味,其中有一道题让我很费解. 原题是:当一 ...

  4. [POJ 2461] Billiard

    同swustoj 11 Billiard Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1362   Accepted: 8 ...

  5. LeetCode Product of Array Except Self (除自身外序列之积)

    题意:给一个序列nums,要求返回一个序列ans,两序列元素个数相同,ans第i个元素就是除了nums[i]之外所有的数相乘之积. 思路:时间O(n),额外空间O(0). 第一次扫一遍,处理nums[ ...

  6. OpenGL学习之路(五)

    1 引子 不知不觉我们已经进入到读书笔记(五)了,我们先对前四次读书笔记做一个总结.前四次读书笔记主要是学习了如何使用OpenGL来绘制几何图形(包括二维几何体和三维几何体),并学习了平移.旋转.缩放 ...

  7. put a ContextMenu into the header of a TabPage z

    publicclassMyTabControl:TabControl { protected override void OnMouseUp(MouseEventArgs e){ if(e.Butto ...

  8. C++基类和派生类之间的转换

    本文讲解内容的前提是派生类继承基类的方式是公有继承,关键字public 以下程序为讲解用例. #include<iostream> using namespace std; class A ...

  9. 位图9宫格 BitmapSlice9.jsfl

    /** * Version 1.1, May 4: fixed issue with symbols in library folders. **/ /** * BitmapSlice9 JSFL b ...

  10. setup.s

    INITSEG = 0x9000 ! we move boot here - out of the way ! 原来 bootsect 所处的段. ! ok, the read went well s ...