Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<list>
- #include<vector>
- #include <queue>
- #include<cstdio>
- #include<algorithm>
- #include<string>
- #include <cmath>
- #include <cctype>
- #define INFINI (1000 * 1000*1000)
- using namespace std;
- const int maxRepresentations=100000;
- struct presentation
- {
- int datedubet,datefin,salle,pos;
- bool operator < (const presentation& str) const
- {
- if(datedubet!=str.datedubet)
- return (datedubet < str.datedubet);
- return datefin<str.datefin;
- }
- };
- presentation planing[maxRepresentations+1];
- int nbSalles,nbRepresentaions;
- list<presentation> salles[101];
- int affectation(int debut,int fin)
- {
- for(int index=1;index<=nbSalles;index++)
- {
- if(salles[index].empty())
- {
- presentation newone={debut,fin,index};
- salles[index].push_back(newone);
- return index;
- }
- else
- {
- list <presentation> :: iterator it;
- bool secondtest=true;
- for(it = salles[index].begin(); it != salles[index].end(); ++it)
- {
- if(!((*it).datedubet>=fin||(*it).datefin<=debut))
- {
- secondtest=false;
- break;
- }
- }
- if(secondtest)
- {
- presentation newone={debut,fin,index};
- salles[index].push_back(newone);
- return index;
- }
- }
- }
- return -1;
- }
- bool acompare(presentation lhs, presentation rhs) { return lhs.pos < rhs.pos; }
- int main()
- {
- ios::sync_with_stdio(false);
- /////////////////////////////////////////////////////don't touch
- cin>>nbSalles>>nbRepresentaions;
- for(int i=1;i<=nbRepresentaions;i++)
- {
- cin>>planing[i].datedubet>>planing[i].datefin;
- planing[i].pos=i;
- }
- sort(planing+1,planing+nbRepresentaions+1);
- for(int i=1;i<=nbRepresentaions;i++)
- {
- int result=affectation(planing[i].datedubet,planing[i].datefin);
- if(result==-1)
- {
- cout<<"NON"<<'\n';
- return 0;
- }
- else
- planing[i].salle=result;
- }
- sort(planing+1,planing+nbRepresentaions+1,acompare);
- cout<<"OUI"<<'\n';
- for(int i=1;i<=nbRepresentaions;i++)
- cout<<planing[i].salle<<" ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement