Advertisement
Ritam_C

End of the Line CP101

Jan 28th, 2021
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define pb push_back
  5. #define p_b pop_back
  6. #define si stack<int>
  7. #define sll stack<ll>
  8. #define sc stack<char>
  9. #define vi vector<int>
  10. #define vll vector<ll>
  11. #define mii map<int, int>
  12. #define msi map<string, int>
  13. #define mci map<char, int>
  14. #define qc queue<char>
  15. #define qi queue<int>
  16. #define qll queue<ll>
  17. using namespace std;
  18.  
  19. int hcf(int a, int b){
  20.     int rem = 1;
  21.     while(true){
  22.         rem = a%b;
  23.         if(rem == 0){
  24.             break;
  25.         }
  26.  
  27.         a = b;
  28.         b = rem;
  29.     }
  30.  
  31.     return b;
  32. }
  33.  
  34. int main(){
  35.     ios_base::sync_with_stdio(false);
  36.     cin.tie(NULL);
  37.     int t;
  38.     cin >> t;
  39.     vector<pair<ll, ll>> v;
  40.     while(t--){
  41.         ll m, c;
  42.         cin >> m >> c;
  43.         v.pb({m, c});
  44.     }
  45.  
  46.     ll count = 0;
  47.     set<pair<string, string>> s;
  48.     for(int i = 0; i < v.size()-1; i++){
  49.         for(int j = i+1; j < v.size(); j++){
  50.             int m1 = v[i].first, c1 = v[i].second, m2 = v[j].first, c2 = v[j].second;
  51.             if(m1 != m2){
  52.                 string x, y;
  53.                 x = to_string(abs((c2-c1)/hcf(c1-c2, m1-m2)))+'/'+to_string(abs((m1-m2)/hcf(c1-c2, m1-m2)));
  54.                 y = to_string(abs((m1*c2-m2*c1)/hcf(m1*c2-m2*c1, m1-m2)))+'/'+to_string(abs((m1-m2)/hcf(m1*c2-m2*c1, m1-m2)));
  55.  
  56.                 if((c1-c2 < 0 && m1-m2 > 0) || (c1-c2 > 0 && m1-m2 < 0)){
  57.                     x = '-'+x;
  58.                 }
  59.  
  60.                 if((m1*c2-m2*c1 < 0 && m1-m2 > 0) || (m1*c2-m2*c1 > 0 && m1-m2 < 0)){
  61.                     y = '-'+y;
  62.                 }
  63.                
  64.  
  65.                 if(c2-c1 == 0){
  66.                     x = "0";
  67.                 }
  68.  
  69.                 if(m1*c2-m2*c1 == 0){
  70.                     y = "0";
  71.                 }
  72.                 s.insert({x, y});
  73.             }
  74.         }
  75.     }
  76.  
  77.     cout << s.size() << "\n";
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement