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
样例解释
输出的数值等于图中红色或紫色框线的三角形的面积。
第一次接触计算几何的题目
先算出两两边的向量 再把向量按照极角来排序 然后用叉乘法一一求面积 更新最小值
#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);i--)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define LL long long
#define pb push_back
#define fi first
#define REP(i,N) for(int i=0;i<(N);i++)
#define CLR(A,v) memset(A,v,sizeof A)
///////////////////////////////////
#define inf 0x3f3f3f3f
#define N 50010
int n; struct node{
long long x,y;
}p[N],temp[N];
bool cmp(node a,node b) {
return b.y*a.x>a.y*b.x;
}
int main() {
scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%lld %lld",&p[i].x,&p[i].y);
}
double ans=pow(,)/;
for(int i=;i<=n;i++) {
int t=;
for(int j=;j<=n;j++) {
if(i==j) continue;
temp[t].x=p[j].x-p[i].x;
temp[t].y=p[j].y-p[i].y;
t++;
}
sort(temp+,temp+t,cmp);
for(int j=;j<t-;j++){
ans=min(ans,(temp[j].x*temp[j+].y-temp[j+].x*temp[j].y)*0.5);
}
}
printf("%.3f",ans);
return ;
}
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 ...
随机推荐
- Ex 2_3 求递推式的通项公式..._第三次作业
- __new__方法和pop方法(判断)
new方法(构造方法)是在函数一加载的时候就被执行,在init方法执行之前被执行 def __new__(cls,*args,**kwargs): if kwargs.pop('many',False ...
- ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies
There are NNN children in kindergarten. Miss Li bought them NNN candies. To make the process more in ...
- ant 安装 网址
1 http://www.testautomationguru.com/jmeter-continuous-performance-testing-part1/ 2 http://www.testau ...
- 如何获取STM32 MCU的唯一ID
前段时间由于应用需要对产品授权进行限制,所以研究了一下有关STM32 MCU的唯一ID的资料,并最终利用它实现了我们的目标. 1.基本描述 在STM32的全系列MCU中均有一个96位的唯一设备标识符. ...
- Oracle+PL+SQL从入门到精通.丁士锋.清华大学出版社.2012
\t第1篇 pl/sql开发入门第1章 oracle 11g数据库系统1.1 关系型数据库系统介绍1.1.1 什么是关系型数据模型1.1.2 数据库系统范式1.1.3 关系型数据库管理系统1.1.4 ...
- Confluence 6 通过 SSL 或 HTTPS 运行 - 为 HTTPS 修改你的 Confluence 基础 URL
在你的浏览器中,进入 > 基本配置(General Configuration). 单击 编辑(Edit). 修改服务器的基础 URL 为 HTTPS.请参考文档 configuring t ...
- Confluence 6 "net.sf.hibernate.PropertyValueException: not-null" 相关问题解决
如果你遇到了下面的错误信息,例如: ERROR [Importing data task] [confluence.importexport.impl.ReverseDatabinder] endEl ...
- Confluence 6 禁用管理员联系表单
如果你希望禁用这个功能,不允许用户通过发送电子邮件的方式联系站点管理员.你可以禁用这个页面中有关输入用户信息发送电子邮件的部分.你只能禁用用户电子邮件输入表单,如果你按照上面描述的步骤在 'Custo ...
- jQuery获取地址栏中的链接参数
http://caibaojian.com/177.html 问题描述 今天做一个主题,有一个需求是根据不同的页面来做,虽然php也可以做到,不过考虑到自己的特效代码都是在jQuery上完成,想着能否 ...