cf468B Two Sets
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.
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).
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).
4 5 9
2 3 4 5
YES
0 0 1 1
3 3 4
1 2 4
NO
It's OK if all the numbers are in the same set, and the other one is empty.
如果A中有了一个x,那么A中也要有a-x,说明(逆否命题)如果A中没有a-x,也就没有x。即如果B中有a-x,就有x。因为不在A就在B咯
所以这个A还是B无所谓的,重要的是x和a-x一定在同一集合,x和b-x一定在同一集合
因此裸并查集,只要被并起来的数字有一个不能在A,那么这一群都不能在A
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,a,b;
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;
}
struct po{LL x;int rnk;}p[];
bool operator <(po a,po b){return a.x<b.x;}
int fa[];
int mrk[];
inline int getfa(int x){return fa[x]==x?x:fa[x]=getfa(fa[x]);}
map<LL,LL>mp;
int main()
{
n=read();a=read();b=read();
for (int i=;i<=n;i++)
{
p[i].x=read();
p[i].rnk=i;
}
sort(p+,p+n+);
for(int i=;i<=n;i++)mp[p[i].x]=p[i].rnk,fa[i]=i,mrk[i]=;
for(int i=;i<=n;i++)
{
if (mp[a-p[i].x])
{
int pos=getfa(mp[a-p[i].x]),pos2=getfa(p[i].rnk);
if (pos!=pos2)fa[pos2]=pos;
}
if (mp[b-p[i].x])
{
int pos=getfa(mp[b-p[i].x]),pos2=getfa(p[i].rnk);
if (pos!=pos2)fa[pos2]=pos;
}
}
for (int i=;i<=n;i++)
{
int ff=getfa(p[i].rnk);
if (!mp[a-p[i].x])mrk[ff]&=;
if (!mp[b-p[i].x])mrk[ff]&=;
}
for (int i=;i<=n;i++)
if (mrk[getfa(i)]==){puts("NO");return ;}
else if (mrk[getfa(i)]==)mrk[getfa(i)]=;
puts("YES");
for (int i=;i<=n;i++)printf("%d ",mrk[getfa(i)]==?:);
puts("");
}
cf468B
cf468B Two Sets的更多相关文章
- TSQL 分组集(Grouping Sets)
分组集(Grouping Sets)是多个分组的并集,用于在一个查询中,按照不同的分组列对集合进行聚合运算,等价于对单个分组使用“union all”,计算多个结果集的并集.使用分组集的聚合查询,返回 ...
- grouping sets从属子句的运用
grouping sets主要是用来合并多个分组的结果. 对于员工目标业绩表'businessTarget': employeeId targetDate idealDistAmount 如果需要分别 ...
- Codeforces 722D. Generating Sets
D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【转】rollup、cub、grouping sets、grouping、grouping_id在报表中的应用
摘自 http://blog.itpub.net/26977915/viewspace-734114/ 在报表语句中经常要使用各种分组汇总,rollup和cube就是常用的分组汇总方式. 第一:gro ...
- salesforce 零基础学习(十九)Permission sets 讲解及设置
Permission sets以及Profile是常见的设置访问权限的方式. Profile规则为'who see what'.通过Profile可以将一类的用户设置相同的访问权限.对于有着相同Pro ...
- Python数据类型之“集合(Sets)与映射(Mapping)”
一.集合类型(Sets) 集合对象是不同的(不可重复)hashable对象的无序集合.常见用法包括:成员关系测试.移除序列中的重复.以及科学计算,例如交集.并集.差分和对称差分.通俗点来说,集合是一个 ...
- 【Swift学习】Swift编程之旅---集合类型之Sets(七)
Sets是存储无序的相同类型的值,你可以在顺序不重要的情况下使用Sets来替代数组,或者当你需要同一个值在集合中只出现一次时. 一.Sets类型语法 写作Set<Element>,Ele ...
- Support for multiple result sets
https://blueprints.launchpad.net/myconnpy/+spec/sp-multi-resultsets Calling a stored procedure can p ...
- CF722D. Generating Sets[贪心 STL]
D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 目后佐道IT教育:教学环境
目后佐道IT教育的品牌故事 http://www.cnblogs.com/itpua/p/7710917.html 目后佐道IT教育的师资团队 http://www.cnblogs.com/itpua ...
- XDU——受教了
存在的问题还是很多的 GG 突然觉得刷题的目的并不是追求A.我们应该在那个过程中提高代码能力和建立模型解题能力 会的算法会巧妙应用才是王道 吐槽自己两句,写高数了
- Educational Codeforces Round 12补题 经典题 再次爆零
发生了好多事情 再加上昨晚教育场的爆零 ..真的烦 题目链接 A题经典题 这个题我一开始推公式wa 其实一看到数据范围 就算遍历也OK 存在的问题进制错误 .. 思路不清晰 两个线段有交叉 并不是端点 ...
- KissXML类库的使用方法
1.添加附件里面的KissXML到工程 2.加入libxml2.dylib 到Frameworks 3.修改工程信息,右击Targets下工程名选“Get Info”,进入修改Header Searc ...
- js 获取当前URL信息
document.location 这个对象包含了当前URL的信息 location.host 获取port号 location.hostname 设置或获取主机名称 location.href 设置 ...
- gEdit - GTK+ 基础文本编辑器
语法 gedit [--help] [--version] [文件名] [文件名] [文件名] 等等... 描述 gEdit 是一个 X窗口系统下的基础文本编辑器由 GTK+ 写成.它现在支持建立,打 ...
- WPF知识点全攻略09- 附加属性
附加属性也是一种特殊的依赖属性. Canvas中的Canvas.Left,Canvas.Top ,DockPanel中DockPanel.Dock等就是附加属性. 更加.NET类属性的写法经验.这个中 ...
- SSIS 通过 WINscp 从SFTP下载文件
1.通过SSIS的process task调用 winscp :C:\Program Files (x86)\WinSCP\WinSCP.exe /script="C:\SFTPFile\T ...
- spring-security中的csrf防御机制(跨域请求伪造)
什么是csrf? csrf又称跨域请求伪造,攻击方通过伪造用户请求访问受信任站点.CSRF这种攻击方式在2000年已经被国外的安全人员提出,但在国内,直到06年才开始被关注,08年,国内外的多个大型社 ...
- Codeforces 727C Guess the Array
题目传送门 长度为\(n\)的数组,询问\(n\)次来求出数组中每一个数的值 我们可以先询问三次 \(a[1]+a[2]\) \(a[1]+a[3]\) \(a[2]+a[3]\) 然后根据这三次询问 ...