City View(UTPC Contest 02-11-22 Div. 2 (Beginner))

City View


UTPC Contest 02-11-22 Div. 2 (Beginner) D: 题目链接.

题目

Sadio has set up a grand night for Valentine’s day. After dinner and dessert, he plans to take his significant other to the top of the tallest building in the city and use the lens he set up there to show his significant other the n places around the city where they had memorable moments (date spots, favorite restaurants, etc).
Sadio goes to test the lens out before the big night and realizes that moving and refocusing the lens takes way too much time. To fix this, he decides to buy a new lens that captures enough of an angle in order to see all n places at the same time. The cost of the lens increases linearly with the angle that it captures (so a lens that captures 90 degrees would cost more than that which captures 89 degrees). Note, when we say that the lens captures x degrees, it is equivalent to having two rays from the origin which make an angle of x degrees, and all the points on/within the two rays are seen.
The city can be represented as a grid where the tallest building (so where Sadio and his partner will be) is at (0,0) and each of the n special points is located at integer coordinates (x,y). Given that Sadio has already spent so much money planning tonight, he wants to spend as little as possible on the new lens. What is the minimum angle such that the lens with that angle can view all n locations? The lens can view a location even if that location is on the very border of what the lens can see.

题意

Sadio为情人节安排了一个盛大的夜晚。在晚餐和甜点之后,他计划把他的另一半带到这个城市最高的建筑顶部,用他在那里设置的镜头向他的另一半展示他们有难忘时刻的城市周围的N个地方(约会地点,最喜欢的餐馆,等等)。
Sadio在这个重要的夜晚之前去测试镜头,发现移动和重新聚焦镜头需要太多的时间。为了解决这个问题,他决定购买一个新的镜头,捕捉足够的角度,以便同时看到所有N个地方。镜头的成本随着捕捉角度的增加而线性增加(所以捕捉90度的镜头会比捕捉89度的镜头成本高)。注意,当我们说镜头捕捉到x度时,它相当于有两条从原点出发的光线,这两条光线形成一个x度的角度,而这两条光线上/内的所有点都被看到。
这个城市可以表示为一个网格,其中最高的建筑(所以Sadio和他的伙伴会在那里)位于(0,0),n个特殊点中的每个都位于整数坐标(x,y)。鉴于Sadio今晚已经花了这么多钱来计划,他希望在新镜头上花的钱越少越好。什么是最小的角度,使具有该角度的镜头能够查看所有的n个地点?镜头可以看到一个地点,即使该地点在镜头所能看到的最边界上。

思路

把输入的每一个点与(0,0)的角度算出,把角度进行一个排序,取角度差最大的一对点和头尾点进行最大值比较,把一个平面坐标系,想成一条线,如图1,蓝色的角度差(相邻角度)最大,即真实角度为360度-去角度差,另外红色部分的角度的真实角度为360度-最大角度+最小角度,红色与蓝色角度进行相比即为题目的解

图1: 在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;

double angle[100005] = {0.0};
double getAngle(double x, double y)
{
    double res = atan2(x, y);
    res = res * 180 / (3.1415926535898);
    if(res < 0){
    	res +=360;
	} 
    return res;
}
int main()
{
    double  x, y;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        angle[i] = getAngle(x, y);
    }
    sort(angle, angle + n);
    double an = 0.0;
    for (int i = 1; i < n; i++)
    {
        if (an < (angle[i] - angle[i - 1]))
        {
            an = angle[i] - angle[i - 1];
        }
    }
    double ans = max(an,360 - angle[n-1] + angle[0]);
    cout << fixed << setprecision(7)<< 360-ans << endl;
}

我应该是全网第一个吧

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值