Codeforces Round #268 (Div. 1) B. Two Sets 暴力

时间:2022-05-22 04:45:15

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里面,就暴力

Codeforces Round #268 (Div. 1) B. Two Sets 暴力

代码:

//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 &num;268 &lpar;Div&period; 2&rpar; D&period; Two Sets &lbrack;stl - set &plus; 暴力&rsqb;

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

  2. Codeforces Round &num;277 &lpar;Div&period; 2&rpar; D&period; Valid Sets 暴力

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

  3. Codeforces Round &num;268 &lpar;Div&period; 2&rpar; ABCD

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

  4. Codeforces Round &num;268 &lpar;Div&period; 1&rpar; A&period; 24 Game 构造

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

  5. 贪心&plus;bfs 或者 并查集 Codeforces Round &num;268 &lpar;Div&period; 2&rpar; D

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

  6. Codeforces Round &num;277 &lpar;Div&period; 2&rpar; D&period; Valid Sets &lpar;DP DFS 思维&rpar;

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

  7. Codeforces Round &num;268 &lpar;Div&period; 2&rpar; (被屠记)

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

  8. Codeforces Round &num;277 &lpar;Div&period; 2&rpar; D&period; 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 &num;268 &lpar;Div&period; 2&rpar;

    补题解: 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. pycharm 2016&period;3 注册码

    Choose Active Code 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYX ...

  2. maven -- 学习笔记(一)之maven环境搭建

    首先先感谢博主的分享http://www.cnblogs.com/yjmyzz/p/3495762.html 基本概念: Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建 ...

  3. iTool拷贝app到电脑上

    iTool拷贝app到电脑上 方法一. iTool找到你的app, 归档在桌面, 桌面就生成了ipa, 其实ipa是一个压缩包, 使用解压软件解压之后 生成Payload文件夹, 点开就可以看到Clo ...

  4. Freemarker中通过request获得contextPath

    <!-- config Freemarker View Resolver--> <bean id="viewResolver" class="org.s ...

  5. 博客迁移到www&period;imyzf&period;com

    本博客已经迁移到www.imyzf.com,本站不再更新,请谅解!

  6. C&plus;&plus;程序设计实践指导1&period;8求指定范围内的所有素数改写要求实现

    改写要求1:以指针为数据结构动态开辟存储空间 #include <cstdlib> #include <iostream> using namespace std; class ...

  7. 使用instantclient&lowbar;11&lowbar;2 和PL&sol;SQL Developer工具包连接oracle 11g远程数据库

    本文转自CSDN博客,http://blog.csdn.net/helifengwell/archive/2010/08/18/5820434.aspx 1,先到Oracle站点下载Instant C ...

  8. Xampp Linux应用

    一.基本操作: 1.Xampp安装包下载:   https://www.apachefriends.org/index.html   2.安装与配置:   将xampp-linux-x64-5.6.3 ...

  9. CentOS命令修改系统时间同步

    使用Centos,遇到本地时间对不上,直接敲命令:date -s "2016-01-08  15:15:15"是立即生效了,但是重启后,系统时间还是原来的. 修改了其一是没有办法奏 ...

  10. Django ORM中,如何使用Count来关联对象的子集数量

    示例models 解决方法 有时候,我们想要获取一个对象关联关系的数量,但是我们不要所有的关联对象,我们只想要符合规则的那些关联对象的数量. 示例models # models.py from dja ...