Cod sursa(job #1074261)
Utilizator | Data | 7 ianuarie 2014 13:43:44 | |
---|---|---|---|
Problema | Balanta | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 3.29 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin("balanta.in");
ofstream fout("balanta.out");
int n, m, rtemp1, rtemp2;
bool f;
fin>>n;
bool temp_max[n], temp_min[n];
for(int i=0; i< n; i++)
{
temp_max[i] = 1;
temp_min[i] = 1;
}
int temp2[n];
for(fin>>m; m>0; m--)
{
fin>>rtemp1;
for(int i = 0; i< 2*rtemp1; i++)
{
fin>>temp2[i];
}
fin>>rtemp2;
if(rtemp2 == 0)
{
f = 0;
for(int i=0; i< n; i++)
{
if(temp_max[i] == 0) f = 1;
}
if(f == 1)
{
for(int i=0; i< 2*rtemp1; i++)
{
temp_max[temp2[i] - 1] = 0;
}
}
f = 0;
for(int i=0; i< n; i++)
{
if(temp_min[i] == 0) f = 1;
}
if(f == 1)
{
for(int i=0; i< 2*rtemp1; i++)
{
temp_min[temp2[i] - 1] = 0;
}
}
}
if(rtemp2 ==1)
{
for(int i=rtemp1; i< 2*rtemp1; i++)
{
temp_max[temp2[i] - 1] = 0;
}
for(int i=0; i< rtemp1; i++)
{
temp_min[temp2[i] - 1] = 0;
}
}
if(rtemp2 ==2)
{
for(int i=rtemp1; i< 2*rtemp1; i++)
{
temp_min[temp2[i] - 1] = 0;
}
for(int i=0; i< rtemp1; i++)
{
temp_max[temp2[i] - 1] = 0;
}
}
}
rtemp1 = 0;
rtemp2 = 0;
for(int i=0; i< n; i++)
{
rtemp1 += temp_max[i];
rtemp2 += temp_min[i];
}
if(rtemp1 == 1 && rtemp2 != 1)
{
for(int i=0; i< n; i++)
{
if(temp_max[i] == 1) fout<<i+1<<endl;
}
}
else
if(rtemp2 == 1 && rtemp1 != 1)
{
for(int i=0; i< n; i++)
{
if(temp_min[i] == 1) fout<<i+1<<endl;
}
}
else fout<<"0"<<endl;
/*(for(int i=0; i< n; i++)
{
cout<<temp_max[i]<<" ";
}
cout<<endl;
for(int i=0; i< n; i++)
{
cout<<temp_min[i]<<" ";
}
cout<<endl;*/
return 0;
}