8161957                 2014-10-10 06:12:37     njczy2010     D - Two Sets             GNU C++     Accepted                 171 ms                 7900 KB    
8156137                 2014-10-09 17:26:01     njczy2010     D - Two Sets             GNU C++     Wrong answer on test 9                 30 ms                 2700 KB    
8156046                 2014-10-09 17:20:58     njczy2010     D - Two Sets             GNU C++     Time limit exceeded on test 1                 1000 ms                 2700 KB    
8155943                 2014-10-09 17:16:09     njczy2010     D - Two Sets             GNU C++     Wrong answer on test 9                 31 ms                 2700 KB    
8154660                 2014-10-09 16:09:13     njczy2010     D - Two Sets             GNU C++     Wrong answer on test 6                 15 ms                 2700 KB

set真是太好用了,55555,要好好学stl

D. Two Sets
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

 
 

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 test(s)
Input
4 5 9 2 3 4 5
Output
YES 0 0 1 1
Input
3 3 4 1 2 4
Output
NO
Note

It's OK if all the numbers are in the same set, and the other one is empty.

题解转自:http://blog.csdn.net/u011353822/article/details/39449071

看到2Set我还真以为用2Set解,后来想想应该是2分匹配图,结果图左右两边分不出来,构不出图,弱爆了。。。唉。。早上起来又掉rating了

看了别人的解题报告,用的是直接暴力,能在a里处理的都放a集合,否则放入b集合,在b里开始遍历,如果b-x不在就去a里拿,如果a中也没有就输出NO,艾玛。。。。。

事实证明有时候想太多也不好

还能用并查集做,膜拜~~~  http://blog.csdn.net/budlele/article/details/39548063

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<string>
//#include<pair> #define N 100005
#define M 1000005
#define mod 1000000007
//#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n,a,b;
map<int,int>mp;
set<int>f,g;
vector<int>c;
int x;
int res[N];
int flag; void ini()
{
memset(res,,sizeof(res));
flag=;
mp.clear();
f.clear();
g.clear();
c.clear();
int i;
int y;
for(i=;i<=n;i++){
scanf("%d",&x);
mp[x]=i;
f.insert(x);
}
for(set<int>::iterator it=f.begin();it!=f.end();it++){
y=*it;
if(f.find(a-y)==f.end()){
c.push_back(y);
//c.push_back(a-y);
}
} for(vector<int>::iterator it=c.begin();it!=c.end();it++){
f.erase(*it);
g.insert(*it);
}
} void solve()
{
while(g.empty()!=){
set<int>::iterator it=g.begin();
int y=*it;
if(g.find(b-y)!=g.end()){
res[ mp[y] ]=;
res[ mp[b-y] ]=;
g.erase(y);g.erase(b-y);
}
else{
if(f.find(b-y)!=f.end()){
res[ mp[y] ]=;
res[ mp[b-y] ]=;
g.erase(y);
f.erase(b-y);
if(f.find( a-(b-y) )!=f.end()){
g.insert(a-(b-y));
f.erase(a-(b-y));
}
}
else{
flag=;return;
}
} }
} void out()
{
if(flag==){
printf("NO\n");
}
else{
printf("YES\n");
printf("%d",res[]);
for(int i=;i<=n;i++){
printf(" %d",res[i]);
}
printf("\n");
}
} int main()
{
// freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
// scanf("%d",&T);
// for(int ccnt=1;ccnt<=T;ccnt++)
// while(T--)
while(scanf("%d%d%d",&n,&a,&b)!=EOF)
{
//if(n==0 && k==0 ) break;
//printf("Case %d: ",ccnt);
ini();
solve();
out();
} return ;
}

Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]的更多相关文章

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

    B. Two Sets Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/B ...

  2. Codeforces Round #268 (Div. 2) ABCD

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

  3. 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 ...

  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. UVA - 1395 Slim Span (最小生成树Kruskal)

    Kruskal+并查集. 点很少,按边权值排序,枚举枚举L和R,并查集检查连通性.一旦连通,那么更新答案. 判断连通可以O(1),之前O(n)判的,第一次写的过了,后来T.. #include< ...

  2. UVA 12563 Jin Ge jin Qu [h] ao 劲歌金曲 (01背包)

    每首只能唱一次,而且中间不能不唱歌,所以先把状态赋值为-1,以区别合法状态和非法状态,在唱歌曲目最多的条件下,离开时间应该尽量晚. 状态定义f[i][j]考虑前i首歌唱歌时间为j的最大唱歌曲目 #in ...

  3. 激活 IDEA, PyCharm

    1. 到网站 http://idea.lanyus.com/ 获取注册码. 2.填入下面的license server: http://intellij.mandroid.cn/ http://ide ...

  4. 国庆集训 || Wannafly Day1

    网址:https://www.nowcoder.com/acm/contest/201#question A.签到 手速石头剪刀布 #include <cstdio> #include & ...

  5. Python基础篇 -- 小数据池和再谈编码

    小数据池 1. id() 通过id()可以查看到一个变量表示的值在内存中的地址 s = "Agoni" print(id(s)) # 2410961093272 2. is 和 = ...

  6. 初识 Hibernate

    Hibernate 框架 1.1   什么是框架? 框架是一个提供了可重用的公共结构半成品. 2.1   关于Hibernate Hibernate是数据持久层的一个轻量级框架.数据持久层的框架有很多 ...

  7. 【贪心 堆】luoguP2672 推销员

    堆维护,贪心做法 题目描述 阿明是一名推销员,他奉命到螺丝街推销他们公司的产品.螺丝街是一条死胡同,出口与入口是同一个,街道的一侧是围墙,另一侧是住户.螺丝街一共有N家住户,第i家住户到入口的距离为S ...

  8. (27)zabbix自定义图表Graph

    zabbix提供了一个自定义图表的功能,这不是废话么?呵呵~前面文章 讲到的<zabbix简易图表>只能显示单个item的数据图表.如果我们想显示多个信息到一个图表上,那必须使用zabbi ...

  9. Re:从零开始的Linux之路(杂谈)

    决定认真从零开始写一个Linux的学习过程,像我这么偷懒的人能写文字记录已经很不容易了,希望不要半途而废吧(拖走) 用多了Linux其实发现,要是哪天Linux和Windows能结合下就好了,简单粗暴 ...

  10. Python9-day3-作业

    ascli  字母,数字.特殊字符,1个字节.8位 unicode:16位 两个字节,升级32位,四个字节 utf-8:最少一个字节 8位,英文字母, 1,有变量name = "aleX l ...