Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define rip(i,a,b) for(int i = a;i<b;i++)
  3. using namespace std;
  4. void printV(vector<pair<int,int>> v){
  5.     rip(i,0,v.size())cout << v[i].first<< " " << v[i].second<<endl;
  6.     cout << endl;
  7. }
  8. int maxPoints(vector<string> points){
  9.     stringstream s;
  10.     vector<pair<int,int>>v;
  11.     s << points[0];
  12.     int n;s>>n;
  13.     int x,y;
  14.     for(int i = 1;i<n+1;i++){
  15.         stringstream ss;
  16.         ss << points[i];
  17.         ss >> x >> y;
  18.         v.push_back({y,x});
  19.     }
  20.     sort(v.begin(),v.end());
  21.     int res = -1;
  22.     set<int> m;
  23.     m.insert(v[0].second);
  24.     for(int i = 1;i<v.size();i++){
  25.         if(v[i].first == v[i-1].first){
  26.             //cout <<v[i].second<< " got here"<<endl;
  27.  
  28.             m.insert(v[i].second);
  29.         }else{
  30.             //cout << "LOL: " << m.count(0)<<endl;
  31.             int c = 0;
  32.             if(m.count(v[i].second))c++;
  33.  
  34.             for(int j = i+1;j<v.size();j++){
  35.                 if(v[j].first != v[j-1].first){
  36.                     res = max(res,c);
  37.                     c = 0;
  38.                 }
  39.                 //if(m[v[j].second])c++;
  40.                 if(m.count(v[j].second))c++;
  41.             }
  42.             res = max(res,c);
  43.             m.clear();
  44.         }
  45.         m.insert(v[i].second);
  46.     }
  47.     return res;
  48. }
  49. int main(){
  50.     int n;
  51.     //cin >> n;
  52.     cout << maxPoints({"20","24331 11582","40676 17095","36278 30532","41086 28684","20917 27058","12962 30532","12962 27058","12686 41706","11904 36954","36278 27058","20917 30532","28688 28593","37112 27058","18069 27058","32436 27058","37390 21596","18069 30532","27549 28756","32436 30532","37112 30532"});
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement