Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #define f(i,n) for(int i =0;i<n;i++)
  2. int maxLength = INT_MIN;
  3. map<pair<int,int>,int>m;
  4. set<pair<int,int> >s;
  5.  
  6. void checkPair(float m,float c){
  7. int count =2;
  8. int i =0;
  9. while(1){
  10. int x = s[i].first;
  11. int y = s[i].second;
  12. float key = m*x+c;
  13. if(key==0){
  14. count++;
  15. s.erase({x,y});
  16. }
  17. else{
  18. i++;
  19. }
  20. if(i>=s.size())
  21. break;
  22. if(s.size()==0)
  23. break;
  24.  
  25. }
  26.  
  27. if(maxLength<count)
  28. maxLength = count;
  29.  
  30. return ;
  31. }
  32.  
  33. void solve(pair<int,int>p1,pair<int,int>p2){
  34. int x1=p1.first;
  35. int x2=p2.first;
  36. int y1=p1.second;
  37. int y2=p2.second;
  38. float m = (float)(y1-y2)/(x1-x2);
  39. float c = y1-m*x1;
  40. s.erase(p1);
  41. s.erase(p2);
  42. checkPair(m,c);
  43. }
  44. int Solution::maxPoints(vector<int> &a, vector<int> &b) {
  45. s.clear();
  46. maxLength = INT_MIN;
  47. int n = a.size();
  48. f(i,n){
  49. s.insert({a[i],b[i]});
  50. }
  51.  
  52. while(1){
  53. solve(s[0],s[1]);
  54. if(s.size()<2)
  55. break;
  56. }
  57.  
  58. return maxLength;
  59.  
  60.  
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement