Last active
March 4, 2016 15:39
-
-
Save ABeltramo/e74f7643e13b88b3ce0d to your computer and use it in GitHub Desktop.
Nimbus3000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// Nimbus3000 | |
// | |
// Created by Ale on 04/03/16. | |
// Copyright © 2016 ABeltramo. All rights reserved. | |
// | |
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
struct Intervallo{ | |
int inizio,fine; | |
}; | |
// compare_intervalli(a,b): | |
// dati due intervalli ritorna true se la fine di a < fine di b | |
// serve per ordinare automaticamente il vettore | |
// vedi sort(...) nel main | |
bool compare_intervalli(const Intervallo &a, const Intervallo &b){ | |
if(a.fine < b.fine) | |
return true; | |
return false; | |
} | |
int N; | |
Intervallo giri[1000]; | |
int main() { | |
ifstream in("input.txt"); | |
ofstream out("output.txt"); | |
in >> N; | |
for (int i=0; i<N; i++) | |
{ | |
in >> giri[i].inizio >> giri[i].fine; | |
} | |
sort(giri,giri+N,compare_intervalli); // Ordino il vettore | |
int fine_attuale = giri[0].fine; | |
int caramelle = 1; | |
for (int i=1; i<N; i++) | |
{ | |
if (fine_attuale < giri[i].inizio) { // Se ne posso aggiungere un altro | |
// fine attuale viene prima dell'inizio del successivo | |
fine_attuale = giri[i].fine; | |
caramelle++; | |
} | |
} | |
out << caramelle << endl ; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.dropbox.com/s/ucuox04ga7kjn1m/Problema.pdf?dl=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment