Test instructions: Give you a number of 1 to n coins, one of which is false, K weighing results, judging and output the number of counterfeit money, can not judge the output 0.
Analysis:
1. The equals sign ' = ' is all real coins on both sides.
2. Counterfeit money cannot be both biased and light.
3. Several unequal weighing counterfeit banknotes appear several times.
AC Code:
#include <stdio.h> #include <string.h> #define MAX 1003int mark[max];struct node{int s; Char c[3]; int a[max>>1],b[max>>1];} Nod[103];int Main () {int n,k; int i,j,l; int t,x,x1,x2; int eq;//The number of equations, while (~SCANF ("%d%d", &n,&k)) {memset (mark,0,sizeof (Mark)); eq=0; input; for (i=0;i<k;i++) {scanf ("%d", &NOD[I].S); for (j=0;j<nod[i].s;j++) scanf ("%d", &nod[i].a[j]); for (j=0;j<nod[i].s;j++) scanf ("%d", &nod[i].b[j]); scanf ("%s", nod[i].c); record equality case; if (nod[i].c[0]== ' = ') {for (j=0;j<nod[i].s;j++) Mark[nod[i].a[j]]=mark[nod[i].b[j]]=1; eq++; } else if (nod[i].c[0]== ' < ') {//unequal becomes a case; all become >. for (j=0;j<nod[i].s;j++) {t=nod[i].a[j]; NOD[I].A[J]=NOD[I].B[J]; nod[i].b[j]=t; } nod[i].c[0]= ' > '; }} t=0; for (i=1;i<=n;i++) if (mark[i]==0) {x1=x2=0; for (j=0;j<k;j++) if (nod[j].c[0]== ' > ') { for (l=0;l<nod[j].s;l++) {if (nod[j].a[l]==i) x1++; if (nod[j].b[l]==i) x2++; }} if (X1&&X2)//counterfeit currency notMay be both biased and light; mark[i]=1; else if (x1==k-eq&&x2==0| | X1==0&&X2==K-EQ) {//satisfy this may be counterfeit money; t++; X=i; }} if (t==1) printf ("%d\n", X); else printf ("0\n"); } return 0;}
POJ 1029 Judging Counterfeit money