Created
December 24, 2013 20:43
-
-
Save LifeMoroz/8117655 to your computer and use it in GitHub Desktop.
This file contains 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
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using std::cout; | |
using std::cin; | |
class Group{ | |
public: | |
Group(){ | |
get_atlets(); | |
kSort(0,mass.size()-1); | |
} | |
int get_number(){ | |
int size = 1; | |
int summ_kg = mass[0].kg; | |
for(unsigned int i = 1; i < mass.size(); ++i){ | |
if(mass[i].mi >= summ_kg){ | |
++size; | |
summ_kg+=mass[i].kg; | |
} | |
} | |
return size; | |
} | |
private: | |
class atlet{ | |
public: | |
int kg,mi; | |
bool operator< (atlet A){ | |
if (this->kg < A.kg) | |
return 1; | |
if (this->kg == A.kg && this->mi>A.mi) | |
return 1; | |
return 0; | |
} | |
bool operator> (atlet A){ | |
if (this->kg > A.kg) | |
return 1; | |
if (this->kg == A.kg && this->mi<A.mi) | |
return 1; | |
return 0; | |
} | |
}; | |
std::vector<atlet> mass; | |
void get_atlets(){ | |
atlet temp; | |
while(cin>>temp.kg>>temp.mi) | |
mass.push_back(temp); | |
} | |
/* void sort(){ | |
//сортируем по массе по возрастанию | |
//дополнительный критерий по силе по убыванию | |
int min; | |
for(int i = 0; i < mass.size(); ++i){ | |
min = i; | |
for(int j = i; j<mass.size(); ++j) | |
if(mass[j].kg < mass[min].kg) | |
min = j; | |
else if (mass[j].kg == mass[min].kg) | |
if(mass[j].mi > mass[min].mi) | |
min = j; | |
atlet temp = mass[min]; | |
mass[min] = mass[i]; | |
mass[i] = temp; | |
} | |
} | |
*/ | |
void kSort(int l, int r) { | |
atlet x = mass[l + (r - l) / 2]; | |
int i = l; | |
int j = r; | |
while(i <= j) | |
{ | |
while(mass[i] < x) i++; | |
while(mass[j] > x) j--; | |
if(i <= j) | |
{ | |
std::swap(mass[i], mass[j]); | |
i++; | |
j--; | |
} | |
} | |
if (i<r) | |
kSort(i, r); | |
if (l<j) | |
kSort(l, j); | |
} | |
}; | |
int main() | |
{ | |
Group my; | |
cout<<my.get_number(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment