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. 2013ACM省赛题目

    地址就贴这一个吧 都在附近 当时回来也没做做 一伤心了 二是当时实在太弱了 先补两道DP E题的区间DP dp[i][j]  截止到i位置以字母j为结束的上升序列 正序 逆序各来一遍 再循环一遍保存一 ...

  2. 设计模式 - interpreter

    interpreter模式在GOF中的定义是:给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子. 定义看起来是非常晦涩.简单来讲,解释器模式通常用于处理特 ...

  3. poj3671

    首先容易想到的是LIS,但是n<=30000,所以肯定要优化: 壮哉单调队列又登场了: 然后再找一个最长不上升序列并求两者最大值即可,复杂度O(n logn); 应该说这是解题通法了,但再回头看 ...

  4. Unity3D中使用3DMAX建模规范

    1.将3Dmax中的单位制设置为厘米.  如果使用3DMax来建模的话,可将3DMax的系统默认单位改成厘米 〉Customize - Units Setup - Metric - Display U ...

  5. ASP.NET的六种验证控件的使用

    C# 中的验证控件分为一下六种 :1 CompareValidator:比较验证,两个字段的值是否相等,比如判断用户输入的密码和确认密码是否一致,则可以用改控件: 2 CustomValidator ...

  6. java中volatitle关键字的作用

    用在多线程,同步变量. 线程为了提高效率,将某成员变量(如A)拷贝了一份(如B),线程中对A的访问其实访问的是B.只在某些动作时才进行A和B的同步.因此存在A和B不一致 的情况.volatile就是用 ...

  7. 【转】 当程序崩溃的时候怎么办 part-1

    转自:http://www.tairan.com/archives/1006 有这样一种情形:当我们正在快乐的致力于我们的app时,并且什么看都是无比顺利,但是突然,坑爹啊,它崩溃了.(悲伤地音乐响起 ...

  8. ejabberd源码流程梳理

    ejabberd的工程主要通过ejabberd.app 组织起来 ejabberd.erl : application:start(ejabberd). ejabberd_app.erl: Mod:s ...

  9. NOIP2004 津津的储蓄计划

    一.津津的储蓄计划 (Save.pas/dpr/c/cpp). [问题描述] 津津的零花钱一直都是自己管理.每个月的月初妈妈给津津300元钱,津津会预算这个月的花销,并且总能做到实际花销和预算的相同. ...

  10. uvalive 3218 Find the Border

    题意:一条封闭折线将平面分成了若干个区域,按顺序给出折线各点的坐标,要求输出封闭折线的轮廓. 题解:用类似卷包裹的算法,先确定一个一定会被选中的点(x坐标最小,y坐标最小)作为起点,然后把可能是下一个 ...