Add a bunch of other problems
This commit is contained in:
183
Educational Codeforces Round 1/C. Nearest vectors.cpp
Normal file
183
Educational Codeforces Round 1/C. Nearest vectors.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
/* Problem URL: https://codeforces.com/contest/598/problem/C */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
#include <ext/pb_ds/assoc_container.hpp>
|
||||
#include <ext/pb_ds/tree_policy.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace __gnu_pbds;
|
||||
|
||||
template <class T, class comp = less<>>
|
||||
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
#define sq(x) ((x)*(ll)(x))
|
||||
|
||||
struct pt { // ponto
|
||||
ll x, y;
|
||||
pt(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
|
||||
bool operator < (const pt p) const {
|
||||
if (x != p.x) return x < p.x;
|
||||
return y < p.y;
|
||||
}
|
||||
bool operator == (const pt p) const {
|
||||
return x == p.x and y == p.y;
|
||||
}
|
||||
pt operator + (const pt p) const { return pt(x+p.x, y+p.y); }
|
||||
pt operator - (const pt p) const { return pt(x-p.x, y-p.y); }
|
||||
pt operator * (const int c) const { return pt(x*c, y*c); }
|
||||
ll operator * (const pt p) const { return x*(ll)p.x + y*(ll)p.y; }
|
||||
ll operator ^ (const pt p) const { return x*(ll)p.y - y*(ll)p.x; }
|
||||
friend istream& operator >> (istream& in, pt& p) {
|
||||
return in >> p.x >> p.y;
|
||||
}
|
||||
};
|
||||
|
||||
struct line { // reta
|
||||
pt p, q;
|
||||
line() {}
|
||||
line(pt p_, pt q_) : p(p_), q(q_) {}
|
||||
friend istream& operator >> (istream& in, line& r) {
|
||||
return in >> r.p >> r.q;
|
||||
}
|
||||
};
|
||||
|
||||
// PONTO & VETOR
|
||||
|
||||
ll dist2(pt p, pt q) { // quadrado da distancia
|
||||
return sq(p.x - q.x) + sq(p.y - q.y);
|
||||
}
|
||||
|
||||
ll sarea2(pt p, pt q, pt r) { // 2 * area com sinal
|
||||
return (q-p)^(r-q);
|
||||
}
|
||||
|
||||
bool col(pt p, pt q, pt r) { // se p, q e r sao colin.
|
||||
return sarea2(p, q, r) == 0;
|
||||
}
|
||||
|
||||
bool ccw(pt p, pt q, pt r) { // se p, q, r sao ccw
|
||||
return sarea2(p, q, r) > 0;
|
||||
}
|
||||
|
||||
int quad(pt p) { // quadrante de um ponto
|
||||
return (p.x<0)^3*(p.y<0);
|
||||
}
|
||||
|
||||
bool compare_angle(pt p, pt q) { // retorna se ang(p) < ang(q)
|
||||
if (quad(p) != quad(q)) return quad(p) < quad(q);
|
||||
return ccw(q, pt(0, 0), p);
|
||||
}
|
||||
|
||||
pt rotate90(pt p) { // rotaciona 90 graus
|
||||
return pt(-p.y, p.x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
V<pair<pt, int>> fds(n);
|
||||
rep(i, n) {
|
||||
cin >> fds[i].first;
|
||||
fds[i].second = i + 1;
|
||||
}
|
||||
|
||||
sort(all(fds), [&](pair<pt, int> &a, pair<pt, int> &b) {
|
||||
return compare_angle(a.first, b.first);
|
||||
});
|
||||
|
||||
auto better = [&](pt &a, pt &b, pt &c, pt &d) {
|
||||
pt p1(a * b, abs(a ^ b));
|
||||
pt p2(c * d, abs(c ^ d));
|
||||
return (p1 ^ p2) > 0;
|
||||
};
|
||||
|
||||
int ans1 = 0;
|
||||
int ans2 = 1;
|
||||
nrep(i, 1, n - 1) {
|
||||
pt &one = fds[i].first;
|
||||
pt &two = fds[i + 1].first;
|
||||
if (better(one, two, fds[ans1].first, fds[ans2].first)) {
|
||||
ans1 = i;
|
||||
ans2 = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
pt &one = fds.back().first;
|
||||
pt &two = fds[0].first;
|
||||
if (better(one, two, fds[ans1].first, fds[ans2].first)) {
|
||||
ans1 = n - 1;
|
||||
ans2 = 0;
|
||||
}
|
||||
|
||||
cout << fds[ans1].second << ' ' << fds[ans2].second << '\n';
|
||||
}
|
||||
Reference in New Issue
Block a user