codeforces 257C解题报告

这破题,开始不知道是算法挂了,和正确答案的差距很小,还以为是精度不够。。
题意:有个初始的坐标(0, 0) 然后有n个人的坐标(xi, yi) 你的任务就是求出最小的扇形的角度,覆盖所有的人,扇形r无限大
一开始直接atan2(y, x)求出角度,然后加PI排个序,最大减最小输出,wa到死。
这题该先存下角度,然后排个序,在枚举最接近的两个点,假设这两个点之间的扇形区域就是我们求的区域的补,那么只需要这个区域最大,答案就最小了
//
//  Created by Matrix on 2016-01-22
//  Copyright (c) 2015 Matrix. All rights reserved.
//
//
//#pragma comment(linker, "/STACK:102400000,102400000")
#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);
//  freopen("out.txt","w",stdout);
#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]));
        }
//      printf("%f\n", res);
        cout << setprecision(10) << res / acos(-1) * 180.0 << endl;
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值