Untitled
unknown
c_cpp
4 years ago
1.3 kB
6
Indexable
#include<bits/stdc++.h> using namespace std; class Solution { public: int maxPoints(int X[], int Y[], int N) { if(N<=2) {return N;} map<double,set<pair<int,int>>>h; set<pair<int,int>>z; int a=0; for(int i=0;i<N;i++) { for(int j=i+1;j<N;j++) { double temp=X[i]-X[j]; if(temp==0) {h[INT_MAX].insert({X[j],Y[j]});} else {h[(double)((Y[i]-Y[j])/temp)].insert({X[j],Y[j]});} } for(auto i: h) { cout<<"Slope= "<<i.first<<"\n"; for(auto j:i.second) { cout<<j.first<<" "<<j.second<<"\n"; } } for(auto it:h) { int e=it.second.size(); a=max(a,e); } h.clear(); } return a+1; } }; int main() { int t; cin>>t; while(t--) { int n,i; cin>>n; int x[n], y[n]; for(i=0;i<n;i++) {cin>>x[i];} for(i=0;i<n;i++) {cin>>y[i];} Solution ob; cout<<ob.maxPoints(x,y,n)<<endl; } }
Editor is loading...