CodeForces 257C View Angle

本文探讨了如何通过原点为中心,最小角度覆盖所有给定坐标点的问题,并提供了实现算法和示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:第一行给出一个数n,下面n行是n个点的坐标,求出以原点为圆心,覆盖所有坐标的最小角度

链接:http://codeforces.com/problemset/problem/257/C

思路:以原点为圆心按角度排序,求出相邻两点之间的最大角度max,最小角度为360-max

注意点:第一点与最后一点之间需要特判


以下为AC代码:

#AuthorProblemLangVerdictTimeMemorySentJudged  
10041611Practice:
luminous11
257C - 18GNU C++11Accepted1746 ms2080 KB2015-02-27 11:06:392015-02-27 11:06:39
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);

bool cmp ( const double &a, const double &b ){
    return a < b;
}
int main()
{
    ios::sync_with_stdio( false );
    int t;
    while ( cin >> t ){
        vector<double> ang;
        double a, b;
        for ( int i = 0; i < t; i ++ ){
            cin >> a >> b;
            double sqr = sqrt( a * a + b * b );
            double tmp = asin ( b / sqr ) * 180.0 / pi;
            if ( a < 1e-6 ){
                tmp = 180 - tmp;
            }
            ang.pb ( tmp );
        }
        sort ( all(ang) );
        double _max = 360.0 - ang[ang.size()-1] + ang[0];
        for ( int i = 1; i < ang.size(); i ++ ){
            _max = max ( _max, ang[i] - ang[i-1] );
        }
        cout << fixed << setprecision(10) << 360.0 - _max << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值