mickypinata

USACO-T022: Ordered Fractions

Nov 29th, 2021
720
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ID: mickyta1
  3. TASK: frac1
  4. LANG: C++
  5. */
  6.  
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9.  
  10. #define f first
  11. #define s second
  12. typedef pair<int, int> pii;
  13.  
  14. bool comp(const pii &lhs, const pii &rhs){
  15.     int l = lhs.f * rhs.s;
  16.     int r = rhs.f * lhs.s;
  17.     return l < r;
  18. }
  19.  
  20. set<pii, decltype(&comp)> stt(comp);
  21.  
  22. int main(){
  23.     freopen("frac1.in", "r", stdin);
  24.     freopen("frac1.out", "w", stdout);
  25.  
  26.     int n;
  27.     scanf("%d", &n);
  28.     stt.emplace(0, 1);
  29.     stt.emplace(1, 1);
  30.     for(int i = 1; i <= n - 1; ++i){
  31.         for(int j = i + 1; j <= n; ++j){
  32.             stt.emplace(i, j);
  33.         }
  34.     }
  35.     for(pii p : stt){
  36.         cout << p.f << '/' << p.s << '\n';
  37.     }
  38.  
  39.     fclose(stdin);
  40.     fclose(stdout);
  41.     return 0;
  42. }
  43.  
RAW Paste Data