codeforces #268 div2 D
对于这道题第一感觉是图论相关
然后我们先分析,假设a[i]在A集合需要的元素是a[x],在B集合是a[y]
那么假设a[i]在A集合,那必然a[x]也必须在A集合,由于a[y]如果在B集合就没有对应元素,则a[y]也一定在A集合
同理,当a[i]在B集合,a[x],a[y]一定也要在B集合
对此我们可以分析出,要想有解,那么a[i],a[x],a[y]必定在同一集合
这样我们可以构造出一堆堆团,每个团都只可能在唯一的集合
那这个团属于那个集合呢?假如这个团有一个元素a[j]它有一个不存在对应在A集合的元素,
那么这个团一定是在B集合的,否则反之;
这样我们也很容易想到什么时候无解,那一定是某个团中既存在一个元素不存在对应在A集合的元素,又存在一个元素不存在对应在B集合的元素
所以就很好解决了,我们用n+1,n+2分别表示不存在对应在A集合的元素,不存在对应在B集合的元素
不难想到用并查集维护团,然后搞定(其实不难,可惜现场nc没想出来)
var ans,a,fa,c:array[..] of longint;
p,q,x,i,n:longint; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; function getf(x:longint):longint;
begin
if fa[x]<>x then fa[x]:=getf(fa[x]);
exit(fa[x]);
end; procedure sort(l,r: longint);
var i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) shr ];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not(i>j) then
begin
swap(a[i],a[j]);
swap(c[i],c[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; function find(x:longint):longint;
var l,r,m:longint;
begin
l:=;
r:=n;
while l<=r do
begin
m:=(l+r) shr ;
if a[m]=x then exit(m);
if a[m]>x then r:=m-
else l:=m+;
end;
exit(-);
end; procedure union(x,y:longint);
var k1,k2:longint;
begin
k1:=getf(x);
k2:=getf(y);
if k1<>k2 then fa[k2]:=k1;
end; begin
readln(n,p,q);
for i:= to n do
begin
read(a[i]);
c[i]:=i;
fa[i]:=i;
end;
fa[n+]:=n+;
fa[n+]:=n+;
sort(,n); for i:= to n do
begin
x:=find(p-a[i]);
if x<>- then union(i,x)
else union(i,n+);
x:=find(q-a[i]);
if x<>- then union(i,x)
else union(i,n+);
end;
if getf(n+)=getf(n+) then
begin
writeln('NO');
halt;
end;
writeln('YES');
for i:= to n do
if getf(i)=getf(n+) then ans[c[i]]:= else ans[c[i]]:=;
for i:= to n do
begin
write(ans[i]);
if i<>n then write(' ');
end;
writeln;
end.
codeforces #268 div2 D的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- tomcat中jsp编译
tomcat运行的工程中,jsp替换文件后可能不起作用.原因是jsp也是需要编译的.编译后的文件存放在tomcat/work文件夹下.如果替换不起作用,可以将work文件夹下的内容删除掉,重新启tom ...
- order by跟group by 跟having----------------sum() 求和 avg()求平均 count() 求个数--------------like
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoEAAACdCAIAAABEujUmAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWX ...
- 消息中间件MQ基础理论知识
欢迎转载,转载请注明出处:http://www.cnblogs.com/lidabnu/p/5723280.html 消息中间件已经流行很长时间,一般情况下,不需要自己来从头研发.设计消息中间件,所以 ...
- .net单元测试——解除依赖
最近在看.net单元测试艺术,我也喜欢单元测试,这里写一下如何在测试中解除对象间的依赖. 假如有这样的一个需求,当用户登陆时,我需要对用户名和密码进行验证,然后再将用户名写入日志中. public c ...
- MVC 中的Areas支持
在ASP.NET MVC 2中对于Area功能的增强,这样的增强是如何在同一个项目中更好地组织应用程序的? ASP.NET MVC 1.0时,如果我们要在一个项目中做自己网站的后台应用,而又保持URL ...
- 关于ASP.Net中路径的问题
比如你的工程是Webapplication1(url是:http://localhost/webapplication1/webform1.aspx) Request.ApplicationPath ...
- C++拷贝构造函数详解 转
一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: [c-sharp] view plaincopy int a = 100; int b = a; 而类对象与普通 ...
- http请求的组成部分
报文流 1.HTTP 报文是在HTTP 应用程序之间发送的数据块.这些数据块以一些文本形式的元信息(meta-information)开头,这些信息描述了报文的内容及含义,后面跟着可选的数据部分.这些 ...
- 我的PHP之旅--XML操作
XML操作 XML主要是做数据存储和WEB服务的,所以我们难免要操作它,这里只介绍PHP的simpleXML方式. 我们要操作的XML: <?xml version="1.0" ...
- iOS 仪表式数字跳动动画-b
前几天搞了 双曲线波浪动画(http://www.jianshu.com/p/7db295fd38eb)和环形倒计时动画(http://www.jianshu.com/p/d1d16dff33c9)而 ...