這破題,開始不知道是算法掛了,和正確答案的差距很小,還以爲是精度不夠。。
題意:有個初始的座標(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;
}