POJ 1029 C++解法
2682 ワード
/* poj 1029 False coin
:
1013, 。 , , 。
:
1013.
1, -1, : 1, -1。
a、 , -- 1, -1
b、 , -- 1, -1;
, -- , 。
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
namespace {
using namespace std;
const int N_MAX = 1000;//
const int K_MAX = 100;//
int C[N_MAX+1][K_MAX]; //
int R[K_MAX]; //
}
int main()
{
int N, K;
//freopen("1.txt","r",stdin);
scanf("%d%d", &N, &K);
int t;
for (int i=0; i<K; i++)
{
int Pi;
scanf("%d", &Pi);
for (int j=0; j<Pi; j++)
{
scanf("%d", &t);
C[t][i] = 1; // 1
}
for (int j=0; j<Pi; j++)
{
scanf("%d", &t);
C[t][i] = -1; // -1
}
char rs[8];
scanf("%s", rs);
//
if (rs[0]=='<') R[i]=-1;
if (rs[0]=='=') R[i]= 0;
if (rs[0]=='>') R[i]= 1;
}
bool bFound = true;
int k=0;
for (int i=1 ; i<=N; i++)
{
int c1=0, c2=0;
for (int j=0; j<K; j++)
{
if (C[i][j] == R[j]) // 1 -1 0
++c1;
if (C[i][j] == -R[j]) // 0 1、 -1
++c2;
if (C[i][j]!=R[j] && C[i][j]!=-R[j]) // 0 0
break;
}
if (c1==K || c2==K) // , 0 i
{
if(k==0)
{
k = i; // ,
}
else
{
bFound = false; // , ,
break;
}
}
}
if (bFound)
printf("%d
", k);
else
printf("0
");
return 0;
}