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 暴力的更多相关文章
-
Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]
8161957 2014-10-10 06:12:37 njczy2010 D - Two Sets GNU C++ A ...
-
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 ...
-
Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
-
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 ...
-
贪心+bfs 或者 并查集 Codeforces Round #268 (Div. 2) D
http://codeforces.com/contest/469/problem/D 题目大意: 给你一个长度为n数组,给你两个集合A.B,再给你两个数字a和b.A集合中的每一个数字x都也能在a集合 ...
-
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 ...
-
Codeforces Round #268 (Div. 2) (被屠记)
c被fst了................ 然后掉到600+.... 然后...估计得绿名了.. sad A.I Wanna Be the Guy 题意:让你判断1-n个数哪个数没有出现.. sb题 ...
-
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 ...
-
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 ...
随机推荐
-
pycharm 2016.3 注册码
Choose Active Code 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYX ...
-
maven -- 学习笔记(一)之maven环境搭建
首先先感谢博主的分享http://www.cnblogs.com/yjmyzz/p/3495762.html 基本概念: Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建 ...
-
iTool拷贝app到电脑上
iTool拷贝app到电脑上 方法一. iTool找到你的app, 归档在桌面, 桌面就生成了ipa, 其实ipa是一个压缩包, 使用解压软件解压之后 生成Payload文件夹, 点开就可以看到Clo ...
-
Freemarker中通过request获得contextPath
<!-- config Freemarker View Resolver--> <bean id="viewResolver" class="org.s ...
-
博客迁移到www.imyzf.com
本博客已经迁移到www.imyzf.com,本站不再更新,请谅解!
-
C++程序设计实践指导1.8求指定范围内的所有素数改写要求实现
改写要求1:以指针为数据结构动态开辟存储空间 #include <cstdlib> #include <iostream> using namespace std; class ...
-
使用instantclient_11_2 和PL/SQL Developer工具包连接oracle 11g远程数据库
本文转自CSDN博客,http://blog.csdn.net/helifengwell/archive/2010/08/18/5820434.aspx 1,先到Oracle站点下载Instant C ...
-
Xampp Linux应用
一.基本操作: 1.Xampp安装包下载: https://www.apachefriends.org/index.html 2.安装与配置: 将xampp-linux-x64-5.6.3 ...
-
CentOS命令修改系统时间同步
使用Centos,遇到本地时间对不上,直接敲命令:date -s "2016-01-08 15:15:15"是立即生效了,但是重启后,系统时间还是原来的. 修改了其一是没有办法奏 ...
-
Django ORM中,如何使用Count来关联对象的子集数量
示例models 解决方法 有时候,我们想要获取一个对象关联关系的数量,但是我们不要所有的关联对象,我们只想要符合规则的那些关联对象的数量. 示例models # models.py from dja ...