poj1029 2010.4.14
假币应该在每个不等式中都出现,最后只要看哪个硬币出现的次数和不等式出现的次数相同,如果这个硬币唯一,那它就是确认的假币。
#include <string>
#include <cstdio>
using namespace std;
#define MAX 1001
int main()
{
int n,k,p,total=0;
char sign;
int t[MAX]={0},r[MAX]={0},w[MAX]={0};
//分别记录 原始数据,标记硬币真假,记录硬币重量;
scanf("%d %d",&n,&k);
int i;
for(i=1;i<=k;i++)
{
scanf("%d",&p);
int j;
for(j=1;j<=2*p;j++)
scanf("%d",&t[j]);
getchar();
scanf("%c",&sign);
if (sign=='=')
{
for(j=1;j<=2*p;j++)
r[t[j]]=1;
}//标记肯定为真的硬币
else
if (sign=='<')
{
total++;
for(j=1;j<=p;j++)
w[t[j]]--;
for(j=p+1;j<=2*p;j++)
w[t[j]]++;
}
else
{
total++;
for(j=1;j<=p;j++)
w[t[j]]++;
for(j=p+1;j<=2*p;j++)
w[t[j]]--;
}
}
int count=0,pos=0;
for(i=1;i<=n;i++)
if (r[i]!=1)
{
if ((w[i]==total)||(w[i]==-total))
{
count++;
pos=i;
}
}
if (count!=1)
printf("0\n");
else
printf("%d\n",pos);
return 0;
}