Pagini recente » Cod sursa (job #3224172) | Cod sursa (job #1039757) | Cod sursa (job #1283382) | Cod sursa (job #1976428) | Cod sursa (job #2771453)
#define MAX_N 800
#include <iostream>
#include <fstream>
#include <tuple>
#include <algorithm>
#include <list>
#include <bitset>
using namespace std;
ifstream fin("overlap.in");
ofstream fout("overlap.out");
int n;
tuple<int, int> A[MAX_N + 1];
int main()
{
fin >> n;
for (int i = 1; i <= n; ++i)
{
fin >> get<0>(A[i]) >> get<1>(A[i]);
}
sort(A + 1, A + n + 1);
for (int k : { 0, 1, 2, 3 })
{
const auto& ApplyNeg = [](tuple<int, int>& XY) { get<0>(XY) *= -1; get<1>(XY) *= -1; };
const auto& ApplyI = [](tuple<int, int>& XY) { const int x = get<0>(XY), y = get<1>(XY); get<0>(XY) = -y; get<1>(XY) = x; };
const auto& ApplyRotation = [&ApplyI, &ApplyNeg, &k](tuple<int, int>& XY) { if (k & 1) { ApplyI(XY); } if (k > 1) { ApplyNeg(XY); } };
for (int i = 1; i <= n; ++i)
{
const tuple<int, int>& offset = make_tuple(get<0>(A[i]) - get<0>(A[1]), get<1>(A[i]) - get<1>(A[1]));
const auto& GetOverlap = [&ApplyRotation, &offset, &i](int index)
{
tuple<int, int> aux = make_tuple(get<0>(A[index]) + get<0>(offset) - get<0>(A[i]), get<1>(A[index]) + get<1>(offset) - get<1>(A[i]));
ApplyRotation(aux);
get<0>(aux) += get<0>(A[i]);
get<1>(aux) += get<1>(A[i]);
const int cnt = index - (lower_bound(A + 1, A + n + 1, A[index]) - A) + 1;
const auto& it = lower_bound(A + 1, A + n + 1, aux);
if (((it + cnt - 1) <= (A + n)) && (*(it + cnt - 1) == aux))
{
const int res = it + cnt - 1 - A;
if (res == index)
{
if ((res < n) && (A[res + 1] == A[index]))
{
return res + 1;
}
else
{
return 0;
}
}
return res;
}
return 0;
};
bitset<MAX_N + 1> V, B;
int cnt = 0;
for (int j = 1; j <= n; ++j)
{
if (!V[j])
{
V[j] = true;
list<int> l;
l.push_back(j);
for (int k = GetOverlap(j); ; k = GetOverlap(k))
{
if ((k == 0) || (k == j))
{
break;
}
else
{
V[k] = true;
l.push_back(k);
}
}
if (l.size() & 1)
{
break;
}
else
{
for (int elem : l)
{
B[elem] = (++cnt) & 1;
}
}
}
}
if (cnt == n)
{
for (int i = 1; i <= n; ++i)
{
fout << (B[i] + 1) << '\n';
}
break;
}
}
}
fin.close();
fout.close();
return 0;
}