这破题,开始不知道是算法挂了,和正确答案的差距很小,还以为是精度不够。。
题意:有个初始的坐标(0, 0) 然后有n个人的坐标(xi, yi) 你的任务就是求出最小的扇形的角度,覆盖所有的人,扇形r无限大
一开始直接atan2(y, x)求出角度,然后加PI排个序,最大减最小输出,wa到死。
这题该先存下角度,然后排个序,在枚举最接近的两个点,假设这两个点之间的扇形区域就是我们求的区域的补,那么只需要这个区域最大,答案就最小了
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <sstream>
#include <set>
#include <vector>
#include <stack>
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x,begin())
#define ll long long
#define CLR(x) memset(x, 0, sizeof x)
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
const int maxv = 1e3 + 10;
const double eps = 1e-10;
const double PI = acos(-1);
double x[maxn], y[maxn];
double angle[maxn];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
int n;
while(cin >> n) {
for(int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
for(int i = 1; i <= n; i++) {
angle[i] = atan2(y[i], x[i]);
}
sort(angle + 1, angle + 1 + n);
double res = 2 * PI;
angle[n+1] = angle[1] + 2.0 * PI;
for(int i = 1; i <= n; i++) {
res = min(res, 2 * PI - fabs(angle[i + 1] - angle[i]));
}
cout << setprecision(10) << res / acos(-1) * 180.0 << endl;
}
return 0;
}