Commit b6a99de1 authored by Sadman Kazi's avatar Sadman Kazi 🎸

Initial commit

parents
*.out
.*.sw*
#include <vector>
#include <map>
#include <iostream>
#define HASH_LIMIT 100
using namespace std;
struct Point {
int x;
int y;
Point() : x(0), y(0) {}
Point(int a, int b) : x(a), y(b) {}
};
class Solution {
public:
int maxPoints(vector<Point>& points) {
std::map<std::vector<Line>, HASH_LIMIT > map;
static int slope;
static int intercept;
for (int i = 0; i < points.size(); i++) {
for (int j = i+1; j < points.size(); j++) {
slope = calcSlope(points[i], points[j]);
intercept = calcIntercept(points[i], slope);
map[key(slope)].push_back(Line(slope, intercept));
}
}
int max = 0;
int cur_max = 0;
for (int i = 0; i < map.size(); i++) {
cur_max = 0;
for (auto iter = map[i].begin(); iter != map[i].end() iter->size() > max; iter++) {
if (iter
}
return 0;
}
private:
static int key(double slope) {
return (int)slope % HASH_LIMIT;
}
static double calcSlope(const Point& a, const Point& b) {
return (double)(a.y - b.y)/(double)(a.x - b.x);
}
static double calcIntercept(const Point& a, const double& slope) {
return a.y - (a.x * slope);
}
};
int main () {
Solution s;
vector<Point> test = { Point(0,0), Point(1,1), Point(2,2), Point(3,3) };
vector<Point> test2 = {Point(-1,2), Point(3,2), Point(4,4), Point(3,1) };
std::cout << s.maxPoints(test) << std::endl;
std::cout << s.maxPoints(test2) << std::endl;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment