Difference between revisions of "Solução: Problema do baile de casais (Antonio Lucas)"

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
(New page: <code lang="cpp"> #include <iostream> #include <vector> #include <string> #include<algorithm> using namespace std; int main() { vector<int> homens, mulheres; int participantes; vect...)
 
 
Line 51: Line 51:
  
  
<\code>
+
</code>

Latest revision as of 14:01, 20 May 2009

#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;
}