Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include<iostream>
  2. #include<list>
  3. #include<vector>
  4. #include <queue>
  5. #include<cstdio>
  6. #include<algorithm>
  7. #include<string>
  8. #include <cmath>
  9. #include <cctype>
  10. #define INFINI (1000 * 1000*1000)
  11. using namespace std;
  12.  
  13.  
  14. const int maxRepresentations=100000;
  15. struct presentation
  16. {
  17. int datedubet,datefin,salle,pos;
  18. bool operator < (const presentation& str) const
  19. {
  20. if(datedubet!=str.datedubet)
  21. return (datedubet < str.datedubet);
  22. return datefin<str.datefin;
  23. }
  24. };
  25. presentation planing[maxRepresentations+1];
  26. int nbSalles,nbRepresentaions;
  27. list<presentation> salles[101];
  28.  
  29.  
  30.  
  31. int affectation(int debut,int fin)
  32. {
  33. for(int index=1;index<=nbSalles;index++)
  34. {
  35. if(salles[index].empty())
  36. {
  37. presentation newone={debut,fin,index};
  38. salles[index].push_back(newone);
  39. return index;
  40. }
  41. else
  42. {
  43. list <presentation> :: iterator it;
  44. bool secondtest=true;
  45. for(it = salles[index].begin(); it != salles[index].end(); ++it)
  46. {
  47. if(!((*it).datedubet>=fin||(*it).datefin<=debut))
  48. {
  49. secondtest=false;
  50. break;
  51. }
  52. }
  53.  
  54. if(secondtest)
  55. {
  56. presentation newone={debut,fin,index};
  57. salles[index].push_back(newone);
  58. return index;
  59. }
  60.  
  61.  
  62. }
  63. }
  64. return -1;
  65. }
  66. bool acompare(presentation lhs, presentation rhs) { return lhs.pos < rhs.pos; }
  67.  
  68. int main()
  69. {
  70. ios::sync_with_stdio(false);
  71. /////////////////////////////////////////////////////don't touch
  72.  
  73.  
  74. cin>>nbSalles>>nbRepresentaions;
  75.  
  76. for(int i=1;i<=nbRepresentaions;i++)
  77. {
  78. cin>>planing[i].datedubet>>planing[i].datefin;
  79. planing[i].pos=i;
  80. }
  81.  
  82.  
  83. sort(planing+1,planing+nbRepresentaions+1);
  84. for(int i=1;i<=nbRepresentaions;i++)
  85. {
  86. int result=affectation(planing[i].datedubet,planing[i].datefin);
  87. if(result==-1)
  88. {
  89. cout<<"NON"<<'\n';
  90. return 0;
  91. }
  92.  
  93. else
  94. planing[i].salle=result;
  95.  
  96. }
  97.  
  98. sort(planing+1,planing+nbRepresentaions+1,acompare);
  99.  
  100. cout<<"OUI"<<'\n';
  101. for(int i=1;i<=nbRepresentaions;i++)
  102. cout<<planing[i].salle<<" ";
  103.  
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement