Pagini recente » Cod sursa (job #2677504) | Cod sursa (job #3040553) | Cod sursa (job #755711) | Cod sursa (job #3256800) | Cod sursa (job #1631079)
#include<fstream>
#define MNOC 1026 // maximum number of coins
using namespace std;
ifstream in("balanta.in");
ofstream out("balanta.out");
int nr_of_coins;
int nr_of_weighings;
int lgH;
bool H[MNOC];
int lgL;
bool L[MNOC];
int lgAB;
bool A[MNOC/2];
bool B[MNOC/2];
int weighing_result; // 0, 1 or 2
int solutionH;
int solutionL;
int number;
void initialize_AB()
{
for (int i=1; i<=nr_of_coins; i++)
A[i]=B[i]=false;
}
void read()
{
in>>nr_of_coins>>nr_of_weighings;
for (int i=1; i<=nr_of_weighings; i++)
{
initialize_AB();
in>>lgAB;
for (int i=1; i<=lgAB; i++)
{
in>>number;
A[number]=true;
}
for (int i=1; i<=lgAB; i++)
{
in>>number;
B[number]=true;
}
in>>weighing_result;
if (weighing_result == 0) // A=B
{
for (int i=1; i<=nr_of_coins; i++)
{
if ((A[i]) || (B[i]))
H[i]=L[i]=true;
}
}
else if (weighing_result == 1) // A>B
{
for (int i=1; i<=nr_of_coins; i++)
{
if (A[i] == H[i])
H[i]=true;
if (B[i] == L[i])
L[i]=true;
}
}
else // A<B
{
for (int i=1; i<=nr_of_coins; i++)
{
if (B[i] == H[i])
H[i]=true;
if (A[i] == L[i])
L[i]=true;
}
}
}
}
void count_lgH_lgL()
{
for (int i=1; i<=nr_of_coins; i++)
{
if (!H[i])
{
lgH++;
solutionH=i;
}
if (!L[i])
{
lgL++;
solutionL=i;
}
}
}
void show()
{
if (lgH + lgL == 1)
out<<max(solutionH, solutionL);
else
out<<0;
}
int main()
{
read();
count_lgH_lgL();
show();
return 0;
}