Advertisement
Guest User

Untitled

a guest
May 14th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdio.h>
  4. #include <vector>
  5. #include <queue>
  6. using namespace std;
  7.  
  8.  
  9. void smista(int N, int nemico[]) {
  10.  
  11. freopen ("input.txt","r",stdin);
  12. freopen ("output.txt","w",stdout);
  13. int aQualeGruppo[N];
  14. bool can[N];
  15. for(int i = 0; i < N; i++)
  16. {
  17. aQualeGruppo[i] = -1; // la persona i appartiene al gruppo 0, 1, 2..
  18. can[N] = true;
  19. }
  20.  
  21. int lastGroup = 0;
  22. int i;
  23. bool canCont = true;
  24. bool firstTime;
  25.  
  26. while(canCont) {
  27.  
  28. canCont = false;
  29. firstTime = true;
  30. for (i = 0; i < N; i++) {
  31.  
  32. // cout << " ------- " << endl;
  33. // cout << aQualeGruppo[i] << ", " << aQualeGruppo[nemico[i]] << ", " << (can[i] ? "si" : "no") << endl;
  34. //cout << " f ---- f" << endl;
  35. if(aQualeGruppo[i] == -1 && aQualeGruppo[nemico[i]] != lastGroup && can[i])
  36. {
  37. if(nemico[i] > i)
  38. can[nemico[i]] = false;
  39.  
  40. aQualeGruppo[i] = lastGroup;
  41. if(!firstTime)
  42. cout << " ";
  43. cout << i;
  44. firstTime = false;
  45. }
  46. can[i] = true;
  47.  
  48. if(aQualeGruppo[i] == -1)
  49. canCont = true;
  50. }
  51. lastGroup++;
  52.  
  53. if(canCont)
  54. cout << endl;
  55. }
  56.  
  57.  
  58.  
  59. }
  60.  
  61. int main1()
  62. {
  63.  
  64.  
  65. freopen ("input.txt","r",stdin);
  66. freopen ("output.txt","w",stdout);
  67.  
  68. int n;
  69. cin >> n;
  70. int nemico[n];
  71.  
  72. for(int i = 0; i < n; i++)
  73. cin >> nemico[i];
  74.  
  75. smista(n, nemico);
  76.  
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement