"BZOJ2199" [Usaco2011 Jan] Dairy Council

Source: Internet
Author: User

Description to farmer John's leadership, the cows withdrew from the farm and formed a dairy council. In the principle of "every cow can get what he wants", the Parliament established the following voting system: M-Only cows (1 <= m <= 4000) will vote for n motions (1 <= N <= 1,000). Each cow will throw "yes" or "no" to exactly two motions b_i and c_i (1 <= b_i <= N; 1 <= c_i <= N) (enter ' Y ' and ' n ' in the file). Their voting results were vb_i (vb_i in {' Y ', ' n '}) and Vc_i (vc_i in {' Y ', ' n '}). Finally, the motion will be decided in the following way: at least one of the two votes cast by each cow matches the final result. For example, Bessie to the motion 1 voted in favor of ' Y ', to the motion 2 voted against ' n ', then in any legal bill through the scheme, must satisfy the motion 1 must be ' Y ' or Bill 2 must be ' N ' (or at the same time satisfy). Give each cow a vote, your job is to determine which motions can be passed and which cannot. If such a scenario does not exist, output "impossible". If there is at least one solution, the output: Y if in each solution, the motion must pass N if in each solution, the motion must be dismissed? If there are solutions to this motion that can be passed, some solutions in which this motion will be dismissed consider the following collection of votes:---------------------1 2 3 cows 1 yes No cows 2 no no cows 3 yes Yes Cows 4 Yes Yes below are two available Energy Solution: * Motion 1 passed (satisfying cow 1,3,4) * Motion 2 dismissed (meet cow 2) * Motion 3 can also be dismissed (this is why there are two solutions) in fact, the above problem has only two solutions. So, the answer to the output is as follows: YN? input* line 1th: Two spaces separated by integers: N and M * 2nd to M+1 lines: Section i+1 describes the voting scheme for the first cow: b_i, vb_i, c_i, vc_ioutput* 1th line: A string with n characters, the first character is either ' Y ' (The first motion must pass), or ' N ' (the first motion must be dismissed), or '? '. If there is no solution, output "impossible". Sample Input
3 4
1 Y 2 N
1 N 2 N
1 y 3 y
1 y 2 y


Sample OutputYN?
2-sat, which points to a point map that must be satisfied by a point that does not meet the criteria, enumerates whether each scheme is feasible
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const Charch[3]={'Y','N','?'};5 Const intn=10000;6 structee{intTo,next;} E[n];7 intopt[n],n,m,head[n],cnt;8 BOOLVis[n];9 voidDfsintx) {Tenvis[x]=1; One      for(intL=head[x];l;l=E[l].next) { A         intv=e[l].to; -         if(!Vis[v]) Dfs (v); -     } the } -  - voidInsertintUintv) { -E[++cnt].to=v; e[cnt].next=head[u];head[u]=CNT; + } -  + BOOLCheckintXintPD) { Amemset (Vis,0,sizeof(Vis)); atDfs2*x-PD); -      for(intI=1; i<=n;i++) -         if(vis[i*2]&&vis[i*2-1])return 0; -     return 1; - } -  in intMain () { -scanf"%d%d",&n,&m); to     Charch1[2],ch2[2]; +      for(intI=1; i<=m;i++){ -         intX,y,xp,yp; thescanf"%d%s%d%s",&x,ch1,&y,ch2); *         if(ch1[0]=='N') x=x*2;Elsex=x*2-1; $         if(ch2[0]=='N') y=y*2;Elsey=y*2-1;Panax Notoginseng         if(%2==0) xp=x-1;Elsexp=x+1; -         if(y%2==0) yp=y-1;Elseyp=y+1;  the Insert (yp,x); insert (xp,y); +     } A      for(intI=1; i<=n;i++){ the         intQ=check (I,0), P=check (I,1);//0 Delegates did not pass, 1 represented by +         if(!P&AMP;&AMP;!Q) {printf ("impossible\n");return 0;} -         if(p&&q) opt[i]=2; $         if(P&AMP;&AMP;!Q) opt[i]=0; $         if(q&!p) opt[i]=1; -     } -      for(intI=1; i<=n;i++) printf ("%c", Ch[opt[i]]); the}

"BZOJ2199" [Usaco2011 Jan] Dairy Council

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.