L3-021 神坛 (30 分)
在古老的迈瑞城,巍然屹立着 n 块神石。长老们商议,选取 3 块神石围成一个神坛。因为神坛的能量强度与它的面积成反比,因此神坛的面积越小越好。特殊地,如果有两块神石坐标相同,或者三块神石共线,神坛的面积为 0.000。
长老们发现这个问题没有那么简单,于是委托你编程解决这个难题。
输入格式:
输入在第一行给出一个正整数 n(3 ≤ n ≤ 5000)。随后 n 行,每行有两个整数,分别表示神石的横坐标、纵坐标(− 横坐标、纵坐标 <)。
输出格式:
在一行中输出神坛的最小面积,四舍五入保留 3 位小数。
输入样例:
8
3 4
2 4
1 1
4 1
0 3
3 0
1 3
4 2
输出样例:
0.500
样例解释
输出的数值等于图中红色或紫色框线的三角形的面积。
暴力解只能对三个测试点,网上查的别人的解法,先按照极角排序,极角就是在极坐标下任意一点M和极点O连线的向量OM和x轴OX的夹角,对于两个含同点向量按照极角排序,按照叉乘积,如果向量1叉乘向量2结果为正,表示向量2在向量1的左边,为0表示共线,否则相反。
已知两共起点向量,求组成三角形面积就是叉乘积取绝对值再乘0.5,因为三角形计算面积有个公式0.5absint。
至于为啥要按照极角排序,应该是省去一些不必要的情况,排好序,只需要相邻俩向量求面积更新最小值即可。
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define inf 1e18
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pa;
int n;
pa point[];
pa line[];
double mp[][];
double ans = inf;
bool cmp(pa a,pa b) {
if(a.first * b.second == b.first * a.second) return a.first < b.first;
return a.first * b.second > b.first * a.second;
}
int main() {
scanf("%d",&n);
for(int i = ;i < n;i ++) {
scanf("%lld%lld",&point[i].first,&point[i].second);
}
for(int i = ;i < n;i ++) {
int t = ;
for(int j = ;j < n;j ++) {
if(i == j) continue;
line[t ++] = pa(point[j].first - point[i].first,point[j].second - point[i].second);
}
sort(line,line + t,cmp);
for(int j = ;j < t;j ++) {
ans = min(ans,0.5 * abs(line[j - ].first * line[j].second - line[j - ].second * line[j].first));
}
}
printf("%.3f",ans);
}
极角排序:https://www.cnblogs.com/aiguona/p/7248311.html
L3-021 神坛 (30 分)的更多相关文章
- PTA 07-图5 Saving James Bond - Hard Version (30分)
07-图5 Saving James Bond - Hard Version (30分) This time let us consider the situation in the movie ...
- PTA 社交网络图中结点的“重要性”计算(30 分)
7-12 社交网络图中结点的“重要性”计算(30 分) 在社交网络中,个人或单位(结点)之间通过某些关系(边)联系起来.他们受到这些关系的影响,这种影响可以理解为网络中相互连接的结点之间蔓延的一种相互 ...
- L3-015 球队“食物链” (30 分)
L3-015 球队“食物链” (30 分) 某国的足球联赛中有N支参赛球队,编号从1至N.联赛采用主客场双循环赛制,参赛球队两两之间在双方主场各赛一场. 联赛战罢,结果已经尘埃落定.此时,联赛主席 ...
- PAT A1127 ZigZagging on a Tree (30 分)——二叉树,建树,层序遍历
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can ...
- 04-树6 Complete Binary Search Tree(30 分)
title: 04-树6 Complete Binary Search Tree(30 分) date: 2017-11-12 14:20:46 tags: - 完全二叉树 - 二叉搜索树 categ ...
- PTA 7-2 二叉搜索树的结构(30 分)
7-2 二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大 ...
- 1127 ZigZagging on a Tree (30 分)
1127 ZigZagging on a Tree (30 分) Suppose that all the keys in a binary tree are distinct positive in ...
- 【PAT】1053 Path of Equal Weight(30 分)
1053 Path of Equal Weight(30 分) Given a non-empty tree with root R, and with weight Wi assigned t ...
- 【PAT】1091 Acute Stroke(30 分)
1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...
- 1115 Counting Nodes in a BST (30 分)
1115 Counting Nodes in a BST (30 分) A Binary Search Tree (BST) is recursively defined as a binary tr ...
随机推荐
- URAL 1658 Sum of Digits
URAL 1658 思路: dp+记录路径 状态:dp[i][j]表示s1为i,s2为j的最小位数 初始状态:dp[0][0]=0 状态转移:dp[i][j]=min(dp[i-k][j-k*k]+1 ...
- Codeforces 832D - Misha, Grisha and Underground
832D - Misha, Grisha and Underground 思路:lca,求两个最短路的公共长度.公共长度公式为(d(a,b)+d(b,c)-d(a,c))/2. 代码: #includ ...
- indexedDB入门
localforage localStorage局限性:存储容量限制,仅支持字符串,如果是存对象还需要将使用JSON.stringify和JSON.parse方法互相转换:读取都是同步的.大多数情况o ...
- 安装 tensorflow 时遇到 OSError: [Errno 1] Operation not permitted 的解决办法
Installing collected packages: numpy, scipy, six, pyyaml, Keras, opencv-python, h5py, html5lib, blea ...
- golang martini 源码阅读笔记之martini核心
继上一篇关于inject注入的笔记,理解了martini的关键核心之一:依赖注入.注入回调函数,由运行时进行主动调用执行.这一篇主要是注解martini的骨架martini.go的实现,下面先从一个简 ...
- 『Sklearn』数据划分方法
原理介绍 K折交叉验证: KFold,GroupKFold,StratifiedKFold, 留一法: LeaveOneGroupOut,LeavePGroupsOut,LeaveOneOut,Lea ...
- ubuntu svn二进制文件
1. 查找2:04时间的日志文件和position. Ps:这里假设我找到的是 mysql-bin.000065 位置开始为1356. 2 复制最近的几个日志文件,从mysql-bin.000065 ...
- PL/SQL 中 dbms_output.put_line 输出字符长度限制的问题
可以使用dbms_out.enable()函数来设定允许的长度. PL/SQL 中 dbms_output.put_line 输出字符长度限制的问题
- OC 类对象和类加载
//------------------------Persion类----------------------------// 1 #import "Person.h" @imp ...
- node -- hapi 学习
node learning 学习node,是为了后续项目可以正常开展,现在写个项目,若不是连接后台,请求数据,一切都不叫着项目了.正好借助掘金的小册,来推进学习 学习资料 YouTube 1 掘金 h ...