Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define f(i,n) for(int i =0;i<n;i++)
- int maxLength = INT_MIN;
- map<pair<int,int>,int>m;
- set<pair<int,int> >s;
- void checkPair(float m,float c){
- int count =2;
- int i =0;
- while(1){
- int x = s[i].first;
- int y = s[i].second;
- float key = m*x+c;
- if(key==0){
- count++;
- s.erase({x,y});
- }
- else{
- i++;
- }
- if(i>=s.size())
- break;
- if(s.size()==0)
- break;
- }
- if(maxLength<count)
- maxLength = count;
- return ;
- }
- void solve(pair<int,int>p1,pair<int,int>p2){
- int x1=p1.first;
- int x2=p2.first;
- int y1=p1.second;
- int y2=p2.second;
- float m = (float)(y1-y2)/(x1-x2);
- float c = y1-m*x1;
- s.erase(p1);
- s.erase(p2);
- checkPair(m,c);
- }
- int Solution::maxPoints(vector<int> &a, vector<int> &b) {
- s.clear();
- maxLength = INT_MIN;
- int n = a.size();
- f(i,n){
- s.insert({a[i],b[i]});
- }
- while(1){
- solve(s[0],s[1]);
- if(s.size()<2)
- break;
- }
- return maxLength;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement