-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtyr.cpp
More file actions
43 lines (38 loc) · 1.15 KB
/
tyr.cpp
File metadata and controls
43 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "bits/stdc++.h"
using namespace std;
#define double long double
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> in(n);
for(auto &ele: in)
cin >> ele.first >> ele.second;
double answer = 1e6;
pair<int, int> indices;
for(int iteration : {-1, 1}) {
vector<int> sorted(n);
iota(sorted.begin(), sorted.end(), 0);
sort(sorted.begin(), sorted.end(), [&](int i, int j) {
auto p = [&](int k) {
return make_pair(in[k].second, in[k].first * iteration);
};
return p(i) < p(j);
});
for(int i = 1; i < n; ++i) {
int xi, xj, yi, yj;
tie(xi, yi) = in[sorted[i]];
tie(xj, yj) = in[sorted[i - 1]];
if(yi != yj) {
if (answer > abs((double)(yi - yj) / (double)(xi - xj))) {
answer = abs((double)(yi - yj) / (double)(xi - xj));
indices = {sorted[i], sorted[i - 1]};
}
}
}
}
int i, j;
tie(i, j) = indices;
cout << i + 1 << " " << j + 1 << "\n";
}