HDU 3532 Max Angle(计算几何——极角排序)

Description

Given manypoints in a plane, two players are playing an interesting game. 

Player1 selects one point A as the vertex(
顶点) of an angle. Then player2 selects other two points Band C. A, B and C are different with each other. Now they get an angle B-A-C. 

Player1 wants to make the angle as large as possible, while player2 wants tomake the angle as small as possible. 

Now you are supposed to find the max angle player1 can get, assuming play2 is clever enough. 

Input

There are manytest cases. In each test case, the first line is an integer n (3 <= n <=1001), which is the number of points on the plane. Then there are n lines. Eachcontains two floating number x, y, witch is the coordinate of one point. n<= 0 denotes the end of input.

Output

For each testcase, output just one line, containing the max angle player1 can get in degreeformat. The result should be accurated up to 4 demicals.

Sample Input

3

0 0

2 0

0 5

-1

Sample Output

90.0000

题意:给一个平面上标许多点,两个表演者正在玩一个有趣的游戏,玩家1选择一个角A作为顶点,玩家2选择B、C两点,A、B、C各不相同,现在他们到达B-A-C,玩家1想使角尽可能的大,玩家2恰恰相反,现在你的任务是找到玩家1的最大角,假设玩家2是非常聪明的

输入:多组测试数据,在每组测试数据中,第一行是一个数字n代表飞机上的点的个数,接下来n行中的每行有两个浮点数,代表点的坐标,n<=0结束

输出:对于每个测试数据,输出一行,包含一个玩家1能够到达的最大角

解题思路:

         由于题意是使玩家1选择的点到其他两点所组成的夹角最大,而玩家2是选择两点使玩家1到该两点夹角最小。

         先定一个A点作为玩家1的点,然后再从余下的n-1个点中选出B、C点两点,即最坏的两个点,那么可以先枚举A点作为外层循环然后再从剩下的点中选出两个最坏的点,选的方法是选用斜率(与X轴的斜率)最相近的两个点,利用排序即可,然后再逐渐选出最大角。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
struct Point
{double x, y;
}p[MAXN];double num[MAXN];
int main()
{int n;while(~scanf("%d",&n)){if(n <= 0)break;for(int i=0; i<n; i++)scanf("%lf%lf",&p[i].x,&p[i].y);double ans = 0;for(int i=0; i<n; i++){int sum = 0;double Min = 5211314;for(int j=0; j<n; j++){if(i == j)continue;double xx = p[j].x - p[i].x;double yy = p[j].y - p[i].y;num[sum] = atan2(yy,xx)/PI*180;///点(yy,xx) 与 X 轴的夹角if(num[sum] < 0)num[sum] += 360;///保证是正数sum++;}sort(num, num+sum);double tmp = 0;for(int j=1; j<sum; j++){tmp = num[j]-num[j-1];///相邻角Min = min(tmp, Min);///最小值//  cout<<"Min1:"<<Min<<endl;// cout<<"tmp1:"<<tmp<<endl;}ans = max(ans, Min);}printf("%.4lf\n",ans);}return 0;
}


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/510429.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

阿里云 ACK 容器服务生产级可观测体系建设实践

ACK 可观测体系介绍 全景概要介绍 上图为 ACK 可观测体系全景图金字塔&#xff0c;从上至下可分为四层&#xff1a; 最上层是最接近用户业务的 Business Monitoring&#xff0c;包括用户业务的前端的流量、PV、前端性能、JS 响应速度等监控。通过容器服务的 IngressDashboard…

中仑网络全站 Dubbo 2 迁移 Dubbo 3 总结

中仑网络在 2022 年完成了服务框架从 Dubbo 2 到 Dubbo 3 的全站升级&#xff0c;深度使用了应用级服务发现、Kubernetes 原生服务部署、服务治理等核心能力。来自中仑网络的技术负责人来彬彬对整个 Dubbo 3 的选型、升级过程及收益等做了深入总结。 来彬彬&#xff0c;2020 年…

hdu3526(最小费用流)

Description Xiao A isbecoming more and more unsatisfied with his computer since he is learninghacker(黑客技术) technologiesthese days but his computer always fails whenever he changes the configurationsof the NIC. He buys a new NIC but the motherboard doe…

hdu3530Subsequence【单调队列优化dp】2010多校联合

Description There is asequence(顺序&#xff0c;序列) of integers.Your task is to find the longest subsequence(子序列) that satisfies the following condition: the differencebetween the maximum element and the minimum element of the subsequence is nosmaller…

基于 OpenYurt 和 EdgeX 的云边端协同新可能

2022 EdgeX 中国挑战赛暨中关村国际前沿科技创新大赛 EdgeX 专题赛正式拉开帷幕。本次大赛分设两大赛道&#xff1a;医疗、教育、消费行业赛道和能源、工业、供应链赛道。大赛致力于构建一个物联网及边缘计算的学习和分享平台&#xff0c;基于 EdgeX Foundry、OpenYurt 等开源技…

OSCAR 2022 开源产业大会PolarDB-X、 PolarDB-PG获奖揭晓

9月16日&#xff0c;OSCAR 2022 开源产业大会在京召开&#xff0c;会议由中国信息通信研究院、中国通信标准化协会主办&#xff0c;中国通信标准化协会云计算标准和开源推进委员会承办。此次会议以“千行百业 可信开源”为主题&#xff0c;邀请上百位专家大咖和国内主流的开源社…

C链表(顺序表、静态链表区别)

#include <stdio.h> #include <stdlib.h> #define LIST_INIT_SIZE 1000 //线性表存储空间的初始分配量 #define LISTINCRESEMENT 100 //线性表存储空间的分配增量 #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int elemType;//元素类型…

HDU3534 给你一个树让你找出其中最长路径以及个数数

Description In the Datastructure class of HEU, the teacher asks one problem: How to find the longestpath(路径) of one treeand the number of such longest path? Input There are several test cases. The firstline of each case contains only one integer N, m…

国庆训练赛

Description Consider the following programming language. This language contains only two types of statements: simple statements and compound statements. The simple statement is in the form “write (literal)”, where “write” is a key word indicating that …

App 隐私合规“免费”自动化检测

一、为什么要进行App隐私合规检测 2021年11月1日《个人信息保护法》正式生效&#xff1b;今年6月14日&#xff0c;国家互联网信息办公室公布《移动互联网应用程序信息服务管理规定》&#xff0c;这是针对App的最强监管新规&#xff0c;于8月1日起正式实施。新规要求应用程序提…

POJ3420 Quad Tiling(模板+矩阵快速幂)

Quad Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4107 Accepted: 1878 Description Tired of(厌烦) the Tri Tiling gamefinally, Michael turns to(转向) a morechallengeable game, Quad Tiling: In how many ways can you tile(铺瓷砖) a 4 …

跨模态学习能力再升级,EasyNLP 电商文图检索效果刷新 SOTA

导读 多模态内容&#xff08;例如图像、文本、语音、视频等&#xff09;在互联网上的爆炸性增长推动了各种跨模态模型的研究与发展&#xff0c;支持了多种跨模态内容理解任务。在这些跨模态模型中&#xff0c;CLIP&#xff08;Contrastive Language-Image Pre-training&#x…

EasyNLP 带你实现中英文机器阅读理解

导读 机器阅读理解是自然语言处理&#xff08;NLP&#xff09;&#xff0c;特别是自然语言理解&#xff08;NLU&#xff09;领域最重要的研究方向之一。自1977年首次被提出以来&#xff0c;机器阅读理解已有近50年的发展史&#xff0c;历经“人工规则”、“传统机器学习”、“…

开关问题(模板+高斯消元)

开关问题Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 7771 Accepted: 3058 Description 有N个相同的开关&#xff0c;每个开关都与某些开关有着联系&#xff0c;每当你打开或者关闭某个开关的时候&#xff0c;其他的与此开关相关联的开关也会相应地发生变化&am…

一文剖析 PolarDB HTAP 的列存数据压缩

前言 数据库迁移上云是大数据时代的一大趋势&#xff0c;PolarDB MySQL是阿里云自研的云原生数据库&#xff0c;主要处理在线事务负载(OLTP, OnLine Transactional Processing)&#xff0c;深受企业用户的青睐。当下&#xff0c;数据分析对于企业的重要性越发显著&#xff1a;…

技术解读:现代化工具链在大规模 C++ 项目中的运用

编者按&#xff1a;C 语言与编译器一直都在持续演进&#xff0c;出现了许多令人振奋的新特性&#xff0c;同时还有许多新特性在孵化阶。除此之外&#xff0c;还有许多小更改以提高运行效率与编程效率。本文整理自全球 C 及系统软件技术大会上的精彩分享&#xff0c;接下来由作者…

扩展的欧几里得算法

任务&#xff1a; 求出A,B的最大公约数&#xff0c;且求出X&#xff0c;Y满足AXBYGCD(A,B). 模板代码&#xff1a; int extendGcd(int a,int b,int &x,int &y) {if(!b){x1;y0;return a;}else{int rextendGcd(b,a%b,y,x);y-x*(a/b);return r;} }

Stein算法(求两个数最大公约数)

欧几里德算法是计算两个数最大公约数的传统算法&#xff0c;他无论从理论还是从效率上都是很好的。但是他有一个致命的缺陷&#xff0c;这个缺陷只有在大素数时才会显现出来。 考虑现在的硬件平台&#xff0c;一般整数最多也就是64位&#xff0c;对于这样的整数&#xff0c;计…

如何将传统 Web 框架迁移部署到 Serverless 架构?

与其说 Serverless 架构是一个新的概念&#xff0c;不如说它是一种全新的思路&#xff0c;一种新的编程范式。 但是原生的 Serverless 开发框架却非常少。以Web框架为例&#xff0c;目前主流的Web框架“均不支持Serverless模式部署”&#xff0c;因此我们一方面要尝试接触Serv…

中国剩余问题(简介+详解)

中国剩余定理 我国古代数学名著《孙子算经》载有一道数学问题&#xff1a;“今有物不知其数&#xff0c;三三数之剩二&#xff0c;五五数之剩三&#xff0c;七七数之剩二。问物几何&#xff1f;”这里的几何指多少的意思。翻译成数学语言就是&#xff1a;求正整数N&#xff0c;…