Solução: Problema do baile de casais (Antonio Lucas)

From AdonaiMedrado.Pro.Br
Revision as of 14:01, 20 May 2009 by 200.17.147.2 (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#include <iostream>
#include <vector>
#include <string>
#include<algorithm>
 
using namespace std;
 
int main() {
	vector<int> homens, mulheres;
	int participantes;
	vector<bool> homens_usados;
 
	cin >> participantes;
 
	for(int i = 0 ; i < participantes ; i++){
		int aux;
		cin >> aux;
		if (aux % 2 == 0) mulheres.push_back(aux);
		else {
			homens.push_back(aux);
			homens_usados.push_back(false);
		}
	}
	sort(mulheres.begin(),mulheres.end());
	sort(homens.begin(),homens.end());
 
 
	for (int i = 0 ; i < mulheres.size(); i++){
		bool achou_par = false;
		for (int j = 0 ; j < homens.size() ; j++){
			if (mulheres[i] < homens[j]){
				if (not homens_usados[j]){
					homens_usados[j] = true;
					achou_par = true;
					break;
				}
			}
		}
		if (not achou_par){
			cout << "F\n";
			return 0;
		}
	}
	cout << "S\n";
 
	return 0;
}