Advertisement
a53

Covoare1

a53
Jun 29th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. using namespace std;
  4. int n,m,p,lin=1,col=1;
  5. vector<pair<int,int>> v;
  6.  
  7. int check(int &x,int &y)
  8. {
  9. if(x<=v[y].first)
  10. return v[y].second;
  11. return 0;
  12. }
  13.  
  14. void get_next(int &dx,int &dy)
  15. {
  16. v[col]={lin+dx-1,dy};
  17. while (true)
  18. {
  19. int aux=check(lin,col);
  20. if(!aux)
  21. return;
  22. col+=aux;
  23. if(col==m+1)
  24. col=1,++lin;
  25. }
  26. }
  27.  
  28. int main()
  29. {
  30. ifstream f("covoare1.in");
  31. f>>n>>m>>p;
  32. v.resize(m+1);
  33. ofstream g("covoare1.out");
  34. for(int i=1,x,y;i<=p;++i)
  35. g<<lin<<' '<<col<< '\n',f>>x>>y,get_next(x, y);
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement