zoukankan      html  css  js  c++  java
  • 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

    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-10 ;
    int Num;
    //const int inf=0first7fffffff;
    const ll inf=999999999;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';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=0;i<n;i++)
        {
            int x=read();p.push_back(x);
            A[x]++;
        }
        for(int i=0;i<n;i++)
        {
            if(A[p[i]]>0&&A[a-p[i]]==0)
                q.push(p[i]);
        }
        while(!q.empty())
        {
            int now = q.front();
            q.pop();
            if(A[now]>0&&A[a-now]==0&&A[b-now]==0)
            {
                cout<<"NO"<<endl;
                return 0;
            }
            --A[now];
            --A[b-now];
            ++B[now];
            ++B[b-now];
            if(A[b-now]==0&&A[a-b+now]>0)
                q.push(a-b+now);
        }
        cout<<"YES"<<endl;
        for(int i=0;i<n;i++)
            if(A[p[i]]>0)
                cout<<"0 ",--A[p[i]];
            else
                cout<<"1 ";
    }
  • 相关阅读:
    my live health
    network / switchboard / jiaohuanji / switch
    my live boadband
    proxyServer Squid 3.5.5 / 20181111
    db mysql / mysql cluster 5.7.19 / performance
    MPTCP v0.92 Release
    MPTCP
    外国专家:区块链是新的Linux 而非新的互联网
    为什么用 Unity 3D 开发游戏是用 C# || JS 开发而不是用C++
    树莓派、 Arduino 、传统单片机开发板该如何选择?
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4828889.html
Copyright © 2011-2022 走看看