Cod sursa(job #1442822)

Utilizator EpictetStamatin Cristian Epictet Data 26 mai 2015 13:02:07
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin ("carpetbomber.in");
ofstream fout ("carpetbomber.out");
int N, tip, Nr_Max = 10000;
pair < int, int > aux;
vector < pair < int, int > > V[1100];

void Solve(int x, int y)
{
    int i, j, poz = 1, nr = 0, pozpos = 0;
    i = j = 0;
    while (poz < 1000000)
    {
        while (V[x][i].first <= poz && i < V[x].size())
        {
            pozpos = max(V[x][i].second, pozpos);
            i++;
        }
        while (V[y][j].first <= poz && j < V[y].size())
        {
            pozpos = max(V[y][j].second, pozpos);
            j++;
        }
        nr += 1;
        poz = pozpos;
    }
    Nr_Max = min(nr, Nr_Max);
}

int main()
{
    fin >> N;
    for (int i = 1; i <= N; i++)
    {
        fin >> tip >> aux.first >> aux.second;
        V[tip].push_back(aux);
    }

    for (int i = 1; i <= N; i++) {
        sort (V[i].begin(), V[i].end());
    }

    for (int i = 1; i <= N; i++)
    {
        if (V[i].empty()) continue;
        for (int j = i + 1; j <= N; j++)
        {
            if (V[j].empty()) continue;
            Solve(i, j);
        }
    }

    fout << Nr_Max << '\n';
    fout.close();
    return 0;
}