From 81f05507cc0b019e5b1021a8313211ea3ff3a4b5 Mon Sep 17 00:00:00 2001 From: Bruno Freitas Tissei <bft15@inf.ufpr.br> Date: Wed, 10 Apr 2019 23:07:36 -0300 Subject: [PATCH] Add geometry functions Signed-off-by: Bruno Freitas Tissei <bft15@inf.ufpr.br> --- algorithms/geometry/geometry_functions.cpp | 22 ++++++++ contests/ICPC_LA18/A.cpp | 2 +- contests/ICPC_LA18/B.cpp | 7 ++- contests/ICPC_LA18/C.cpp | 3 +- contests/ICPC_LA18/D.py | 3 +- contests/ICPC_LA18/E.cpp | 60 ++++++++++++++++++++++ contests/ICPC_LA18/L.cpp | 4 +- contests/ICPC_LA18/M.cpp | 6 +-- contests/ICPC_LA18/out | 1 - 9 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 algorithms/geometry/geometry_functions.cpp create mode 100644 contests/ICPC_LA18/E.cpp delete mode 100644 contests/ICPC_LA18/out diff --git a/algorithms/geometry/geometry_functions.cpp b/algorithms/geometry/geometry_functions.cpp new file mode 100644 index 0000000..97b6abe --- /dev/null +++ b/algorithms/geometry/geometry_functions.cpp @@ -0,0 +1,22 @@ +/** + * Geometry functions + */ + +struct Vector { + double x, y; + + Vector(double x, double y) : x(x), y(y) {} + + double dot_product(Vector v) { return x * v.x + y * v.y; } + double cross_product(Vector v) { return x * v.y - v.x * y; } + + /** + * Returns angle between this and v. + */ + double angle(Vector v) { + + // atan2(y, x) is in the range [-180,180]. To get [0, 360], + // atan2(-y, -x) + 180 is used + return ((atan2(-cross_product(v), -dot_product(v)) * 180.0) / M_PI) + 180.0; + } +}; diff --git a/contests/ICPC_LA18/A.cpp b/contests/ICPC_LA18/A.cpp index a044d35..7be4b85 100644 --- a/contests/ICPC_LA18/A.cpp +++ b/contests/ICPC_LA18/A.cpp @@ -19,7 +19,6 @@ using namespace std; using ll = long long; using ii = pair<int,int>; - int main() { ios::sync_with_stdio(0); cin.tie(0); @@ -27,6 +26,7 @@ int main() { string s; cin >> s; s.erase(s.begin() + s.size() - 3); stringstream x(s); + int r; x >> r; cout << 36000 / __gcd(36000, r) << ende; diff --git a/contests/ICPC_LA18/B.cpp b/contests/ICPC_LA18/B.cpp index af4e17d..86e86c2 100644 --- a/contests/ICPC_LA18/B.cpp +++ b/contests/ICPC_LA18/B.cpp @@ -34,17 +34,16 @@ int main() { if (pref.back() % 2) return cout << "N" << ende, 0; - int beg = 0; - vector<ii> found; + int beg = 0, ans = 0; for (int i = 0; i < n; ++i) { while (beg < i && pref[i] - pref[beg] > pref.back() / 2) beg++; if (pref[i] - pref[beg] == (pref.back() / 2)) - found.pb(ii(beg, i)); + ans++; } - if (found.size() >= 2) + if (ans >= 2) cout << "Y" << ende; else cout << "N" << ende; diff --git a/contests/ICPC_LA18/C.cpp b/contests/ICPC_LA18/C.cpp index cf66180..2394c73 100644 --- a/contests/ICPC_LA18/C.cpp +++ b/contests/ICPC_LA18/C.cpp @@ -25,8 +25,7 @@ int d[MAX], c[MAX]; int dp[MAX][6][123]; int fix(int x) { - if (x > 120) return 121; - else return x; + return min(x, 121); } int solve(int i, int state, int mi) { diff --git a/contests/ICPC_LA18/D.py b/contests/ICPC_LA18/D.py index c536ec0..7032c5f 100644 --- a/contests/ICPC_LA18/D.py +++ b/contests/ICPC_LA18/D.py @@ -1,7 +1,6 @@ n = int(input()) every = [] for i in range(n): - s = input() - x = s.split('@') + x = input().split('@') every += [ x[0].split('+')[0].replace('.','') + x[1] ] print(len(set(every))) diff --git a/contests/ICPC_LA18/E.cpp b/contests/ICPC_LA18/E.cpp new file mode 100644 index 0000000..83a7595 --- /dev/null +++ b/contests/ICPC_LA18/E.cpp @@ -0,0 +1,60 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +using ll = long long; +using ii = pair<int,int>; + +struct Point { + double x, y; + Point() {} + Point(double x, double y) : x(x), y(y) {} + Point operator-(Point a) { return Point(x - a.x, y - a.y); } +}; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + ll n; cin >> n; + vector<Point> v(n); + for (auto &i : v) + cin >> i.x >> i.y; + + ll ans = (n * (n - 1LL) * (n - 2LL)) / 6LL; + for (int i = 0; i < n; ++i) { + ll l = i + 1, r = i + n - 1; + + for (int j = 0; j < 20; ++j) { + ll m = (l + r) / 2; + + Point a = v[(i+1)%n] - v[i]; + Point b = v[(m+1)%n] - v[m%n]; + + double ang = (atan2(-(a.x*b.y - a.y*b.x), -(a.x*b.x + a.y*b.y)) * 180.0) / M_PI + 180.0; + if (ang > 180.0) + r = m; + else + l = m; + } + + ans -= ((l - i) * (l - i - 1LL)) / 2LL; + } + + cout << ans << ende; + return 0; +} diff --git a/contests/ICPC_LA18/L.cpp b/contests/ICPC_LA18/L.cpp index 134cd18..af7e048 100644 --- a/contests/ICPC_LA18/L.cpp +++ b/contests/ICPC_LA18/L.cpp @@ -107,7 +107,9 @@ int main() { for (auto i : que) { while (curr >= 0 && primes[curr] > i.fi.fi) { for (int j = primes[curr]; j <= N; j += primes[curr]) - if (query(j, j) != 0) update(j, -1); + if (query(j, j) != 0) + update(j, -1); + curr--; } diff --git a/contests/ICPC_LA18/M.cpp b/contests/ICPC_LA18/M.cpp index 9813471..b8db631 100644 --- a/contests/ICPC_LA18/M.cpp +++ b/contests/ICPC_LA18/M.cpp @@ -19,21 +19,19 @@ using namespace std; using ll = long long; using ii = pair<int,int>; - int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; - int past = 0; - int ans = 0; + int past = 0, ans = 0; for (int i = 0; i < n; ++i) { int x; cin >> x; if (x > past) ans++; past = x; } - cout << ans << ende; + cout << ans << ende; return 0; } diff --git a/contests/ICPC_LA18/out b/contests/ICPC_LA18/out deleted file mode 100644 index 8a7ce29..0000000 --- a/contests/ICPC_LA18/out +++ /dev/null @@ -1 +0,0 @@ -361391 -- GitLab