artemgf

Команда супергероев

Oct 28th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <map>
  7. #include <queue>
  8. using namespace std;
  9.  
  10. #define MAX 100
  11. struct k
  12. {
  13.     int num, want;
  14. };
  15.  
  16. bool D(k p1, k p2)
  17. {
  18.     return p1.want < p2.want;
  19. }
  20. int main()
  21. {
  22.     int n, prom;
  23.     map <int, vector<int>> teams;
  24.     vector <k> promg;
  25.     vector <int> sameteam;
  26.     k promk;
  27.     cin >> n;
  28.  
  29.     for (int i = 1; i <= n; i++)
  30.     {
  31.         cin >> prom;
  32.         promk.num = i;
  33.         promk.want = prom;
  34.         promg.push_back(promk);
  35.     }
  36.  
  37.     sort(promg.begin(), promg.end(), D);
  38.  
  39.     int lastwant= promg.begin()->want;
  40.     sameteam.push_back(promg.begin()->num);
  41.     int allteam=0;
  42.     for (auto i = promg.begin()+1; i != promg.end(); i++)
  43.     {
  44.         if (lastwant != i->want)
  45.         {
  46.             if (sameteam.size() == lastwant)
  47.             {
  48.                 allteam++;
  49.                 teams[lastwant] = sameteam;
  50.             }
  51.             else
  52.                 if (sameteam.size() > lastwant&&sameteam.size() < i->want)
  53.                 {
  54.                     teams[sameteam.size()] = sameteam;
  55.                     allteam++;
  56.                 }
  57.             lastwant = i->want;
  58.         }
  59.         sameteam.push_back(i->num);
  60.     }
  61.  
  62.  
  63.     if (sameteam.size() == lastwant)
  64.     {
  65.         allteam++;
  66.         teams[lastwant] = sameteam;
  67.     }
  68.     else
  69.         if (sameteam.size() > lastwant)
  70.         {
  71.             teams[sameteam.size()] = sameteam;
  72.             allteam++;
  73.         }
  74.  
  75.     cout << allteam << endl;
  76.  
  77.     for (auto i = teams.begin(); i != teams.end(); i++)
  78.     {
  79.         cout << i->first << " ";
  80.         for (auto j = i->second.rbegin(); j != i->second.rend(); j++)
  81.             cout << *j << " ";
  82.         cout << endl;
  83.     }
  84.  
  85.     _getch();
  86.     return 0;
  87. }
Add Comment
Please, Sign In to add comment