From 20df0aa1edab2daa0661cab2a3f8b9d10a715f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ndor=20Dar=C3=B3czi?= <83545679+daroczisandor@users.noreply.github.com> Date: Tue, 23 Nov 2021 00:13:19 +0100 Subject: [PATCH] Create solution.cpp --- Codechef/2-D Point Meeting/solution.cpp | 263 ++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 Codechef/2-D Point Meeting/solution.cpp diff --git a/Codechef/2-D Point Meeting/solution.cpp b/Codechef/2-D Point Meeting/solution.cpp new file mode 100644 index 0000000..559751c --- /dev/null +++ b/Codechef/2-D Point Meeting/solution.cpp @@ -0,0 +1,263 @@ +#include +#include + +#define ll long long + +using namespace std; + +int root(int k) { + int sq = floor(sqrt((float)(1+8*k))); + return (1+sq)/2; +} + +bool on_line(ll x1, ll y1, ll x2, ll y2, int dir) { + if (dir == 1) return (y1 == y2); + if (dir == 2) return (x1 == x2); + if (dir == 3) return (x2-x1 == y2-y1); + if (dir == 4) return (x1+y1 == x2+y2); +} + +pair intersection(ll x1, ll y1, int dir1, ll x2, ll y2, int dir2) { + + ll p1, p2, q1, q2, r1, r2; + + switch(dir1) { + case 1: + p1 = 0; q1 = 1; + break; + case 2: + p1 = 1; q1 = 0; + break; + case 3: + p1 = 1; q1 = -1; + break; + case 4: + p1 = 1; q1 = 1; + } + + switch(dir2) { + case 1: + p2 = 0; q2 = 1; + break; + case 2: + p2 = 1; q2 = 0; + break; + case 3: + p2 = 1; q2 = -1; + break; + case 4: + p2 = 1; q2 = 1; + } + + r1 = p1*x1 + q1*y1; + r2 = p2*x2 + q2*y2; + + ll x = (q2*r1 - q1*r2)/(p1*q2 - p2*q1); + ll y = (p1*r2 - p2*r1)/(p1*q2 - p2*q1); + + return {x,y}; + +} + +int main() +{ + + int t; + cin >> t; + + while(t--) { + + int n; + cin >> n; + +// auto p = intersection(0,0,3,4,2,1); +// cout << "int: " << p.first << " " << p.second << "\n"; + + map, int>, set>> line_to_normal_points; + map, int>, set>> line_to_all_points; + map, int> scores; + set> points; + vector, int>> lines; + + ll x[n], y[n]; + for (int i = 0; i> c; + x[i] = 2*c; + } + for (int i = 0; i> c; + y[i] = 2*c; + } + + for (int i = 0; ifirst); +// auto p = line.first; +// int dir = line.second; +// auto s = (it->second); +// +// cout << "line_to_all_points: \n"; +// +// cout << "line: " << p.first << " " << p.second << " " << dir << "\n"; +// cout << "points: \n"; +// for (auto elem : s) { +// cout << elem.first << " " << elem.second << "\n"; +// } +// +// +// } + +// for (auto it = line_to_normal_points.begin(); it != line_to_normal_points.end(); ++it) { +// +// auto line = (it->first); +// auto p = line.first; +// int dir = line.second; +// auto s = (it->second); +// +// cout << "line_to_normal_points: \n"; +// +// cout << "line: " << p.first << " " << p.second << " " << dir << "\n"; +// cout << "points: \n"; +// for (auto elem : s) { +// cout << elem.first << " " << elem.second << "\n"; +// } +// +// +// } + + for (auto it = line_to_normal_points.begin(); it != line_to_normal_points.end(); ++it) { + + auto line = (it->first); + auto s0 = (it->second); + int sz = s0.size(); + + //cout << "line: " << (line.first).first << " " << (line.first).second << " " << line.second << " size: " << sz << "\n"; + + auto s = line_to_all_points[line]; + for (auto it2 = s.begin(); it2 != s.end(); ++it2) { + + auto p = *it2; + + scores[p] += sz; + + if (points.find(p) != points.end()) { + scores[p]--; + } + +// if (p.first == 0 && p.second == 1) cout << "pair 0 1: line: " << (line.first).first << " " << (line.first).second << " " << line.second << " size: " << sz << "\n"; + + } + + } + + int mx = 0; + for (auto it = scores.begin(); it != scores.end(); ++it) { + + int val = (it->second); +// cout << "point: " << (it->first).first << " " << (it->first).second << " val: " << val << "\n"; + if (val > mx) mx = val; + + } + + cout << 2*n-mx << "\n"; + + + + + } + + return 0; +}