Advertisement
a53

Numereiajb

a53
Oct 12th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <fstream>
  2. #include <queue>
  3. using namespace std;
  4.  
  5. ifstream fin ("numereiajb.in");
  6. ofstream fout ("numereiajb.out");
  7.  
  8. long long a,b,n,i,j,crt[2],last,nr;
  9.  
  10. queue <pair <long long, long long> > Q[2];
  11.  
  12. int main()
  13. {
  14. fin>>a>>b>>n;
  15. Q[0].push(make_pair(1,0));
  16. Q[1].push(make_pair(0,1));
  17. for(int t=1;t<=n;++t)
  18. {
  19. for(int j=0;j<2;++j)
  20. crt[j]=Q[j].front().first*a+Q[j].front().second*b;
  21. if(crt[0]<crt[1])
  22. {
  23. i=Q[0].front().first;
  24. j=Q[0].front().second;
  25. Q[0].pop();
  26. nr=crt[0];
  27. }
  28. else
  29. {
  30. i=Q[1].front().first;
  31. j=Q[1].front().second;
  32. Q[1].pop();
  33. nr=crt[1];
  34. }
  35. if(nr==last)
  36. {
  37. --t;
  38. continue;
  39. }
  40. last = nr;
  41. fout<<i<<' '<<j<<'\n';
  42. Q[0].push(make_pair (i+1,j));
  43. Q[1].push(make_pair (i,j+1));
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement