rt,经检验,精度在1e-16时出现误差,问如何避免
# include <bits/stdc++.h>
# define I return
# define AK 0
# define IOI ;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, int> pdi;
const long double pi = acos (-1);
int n, x, y, mini;
long double minx = 100, angle;
pdi a[100005];
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> n;
for (int i = 0; i < n; ++ i)
cin >> x >> y, a[i] = {atan2 (y, x), i + 1};
sort (a, a + n);
a[n] = {2 * pi + a[0].first, a[0].second};
for (int i = 0; i < n; ++ i)
if ((angle = a[i + 1].first - a[i].first) < minx)
minx = angle, mini = i;
// for (int i = 0; i < n; ++ i) cout << fixed << setprecision (16) << a[i].second << ',' << a[i + 1].second << ':' << a[i + 1].first - a[i].first << '\n';
cout << a[mini].second << ' ' << a[mini + 1].second;
I AK IOI
}
/*
4
-6427 -6285
-5386 -5267
-3898 7239
-3905 7252
*/
Hack.in
4
-6427 -6285
-5386 -5267
-3898 7239
-3905 7252
Hack.ans
4 3
my.out
2 1