New Ket-2018 Multi-school algorithm fifth field D-Set problem + check set

Source: Internet
Author: User

Collection issues

Test instructions

Give you A, B and n number P[i], ask how you assign this n number to a A, a, and meet:

If X is in set a, then A-x must also be in collection A.

If x is in set B, then b-x must also be in set B.

Train of thought: and check the operation, oneself mainly did not think to use map to map 1e9-->1e5;

#include <iostream>#include<cstring>#include<string>#include<algorithm>#include<cstdio>#include<map>using namespacestd;Const intMAXN = 1e5+7;intN,a,b,fa[maxn],a[maxn];map<int,int>MP;voidinit () { for(intI=0; i<=n+1; i++) Fa[i]=i;}intFindintx) {    if(fa[x]==x)returnx; Else returnFA[X] =find (Fa[x]);}voidUniintXinty) {    intPX =find (x); intPY =find (y); if(px==py)return; ElseFA[PX] =py;}intMain () {scanf ("%d%d%d",&n,&a,&B); intMax1 =0;  for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); Mp[a[i]]=i; Max1=Max (max1,a[i]); }    if(max1>=Max (A, b)) {returnprintf"no\n"),0;} Else{init ();  for(intI=1; i<=n;i++)            {                if(mp[b-A[i]]) Uni (i,mp[b-A[i]]); ElseUni (i,0); if(mp[a-A[i]]) Uni (i,mp[a-A[i]]); ElseUni (i,n+1); }            intAF = Find (0); intBF = Find (n+1); if(af==BF) {                returnprintf"no\n"),0; }            Else{printf ("yes\n");  for(intI=1; i<=n;i++)                {                    if(i!=1) printf (" "); if(Af==find (i)) printf ("0"); Elseprintf"1"); } printf ("\ n"); }        }    return 0;}

New Ket-2018 Multi-school algorithm fifth field D-Set problem + check set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.