Pagini recente »
Istoria paginii runda/2019-03-24-test-6/clasament
|
2020-04-25-clasa-5-tema-35
|
Monitorul de evaluare
|
Istoria paginii runda/2024-11-30-clasa-6-concurs03/clasament
|
Cod sursă (job #321902)
Cod sursă (job
#321902)
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2048 + 1;
struct Canibal
{
int X, Y, Z, T;
bool operator < (const Canibal& A) const
{
return (X < A.X && Y < A.Y && Z < A.Z && T < A.T);
}
bool operator == (const Canibal& A) const
{
return (X == A.X && Y == A.Y && Z == A.Z && T == A.T);
}
};
Canibal C[Nmax];
vector<int> G[2 * Nmax];
bool used[2 * Nmax];
int L[2 * Nmax], R[2* Nmax];
int N;
bool validEdge(int x, int y)
{
if (C[y] == C[x])
return x < y;
return C[y] < C[x];
}
bool pairUp(int nod)
{
if (used[nod])
return false;
used[nod] = true;
for (auto son: G[nod])
if (!R[son])
{
L[nod] = son;
R[son] = nod;
return true;
}
for (auto son: G[nod])
if (pairUp(R[son]))
{
L[nod] = son;
R[son] = nod;
return true;
}
return false;
}
int matching()
{
bool change;
do
{
change = false;
memset(used, 0, sizeof(used));
for (int i = 1; i <= 2 * N; ++i)
if (!L[i])
change |= pairUp(i);
}
while (change);
int nr_c = 0;
for (int i = 1; i <= 2 * N; ++i)
nr_c += (L[i] > 0);
return nr_c;
}
int main()
{
ifstream in("canibali.in");
ofstream out("canibali.out");
cin >> N;
for (int i = 1; i <= N; ++i)
in >> C[i].X >> C[i].Y >> C[i].Z >> C[i].T;
for (int i = 1; i <= N; ++i)
for (int j = 1; j <= N; ++j)
{
if (validEdge(i, j))
{
G[i].push_back(j);
G[i + N].push_back(j);
}
}
cout << N - matching();
return 0;
}