在古老的迈瑞城,巍然屹立着 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 分)的更多相关文章

  1. 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 ...

  2. PTA 社交网络图中结点的“重要性”计算(30 分)

    7-12 社交网络图中结点的“重要性”计算(30 分) 在社交网络中,个人或单位(结点)之间通过某些关系(边)联系起来.他们受到这些关系的影响,这种影响可以理解为网络中相互连接的结点之间蔓延的一种相互 ...

  3. L3-015 球队“食物链” (30 分)

    L3-015 球队“食物链” (30 分)   某国的足球联赛中有N支参赛球队,编号从1至N.联赛采用主客场双循环赛制,参赛球队两两之间在双方主场各赛一场. 联赛战罢,结果已经尘埃落定.此时,联赛主席 ...

  4. 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 ...

  5. 04-树6 Complete Binary Search Tree(30 分)

    title: 04-树6 Complete Binary Search Tree(30 分) date: 2017-11-12 14:20:46 tags: - 完全二叉树 - 二叉搜索树 categ ...

  6. PTA 7-2 二叉搜索树的结构(30 分)

    7-2 二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大 ...

  7. 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 ...

  8. 【PAT】1053 Path of Equal Weight(30 分)

    1053 Path of Equal Weight(30 分) Given a non-empty tree with root R, and with weight W​i​​ assigned t ...

  9. 【PAT】1091 Acute Stroke(30 分)

    1091 Acute Stroke(30 分) One important factor to identify acute stroke (急性脑卒中) is the volume of the s ...

  10. 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 ...

随机推荐

  1. [转]mysql日常工作手记

    1. 给navy加show权限: 1 2 update mysql.user set Show_db_priv='Y'  where user='navy'; flush privileges; 2. ...

  2. 3-23 Rspec自动化测试(开始练习)

    闰年程序 leap_year_spec.rb require_relative './leap_year' describe "Leap Year" do it "201 ...

  3. week 1

    day1 订正 学习AC自动机 day2 mobius反演 对偶图 codeforces day3 ZR模拟赛 订正 day4 复习AC自动机 题库 https://www.cnblogs.com/c ...

  4. cf188C(最大子段和&&思维)

    C. Functions again time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Repeater中服务器按钮

    protected void Button1_Click(object sender, EventArgs e)        {            Button btn = sender as ...

  6. ajax缓存和编码问题

    ajax缓存问题,工作中几乎使用ajax都会碰到,虽然解决缓存问题很多,但我 一直使用常用的,方便理解的,没有多大记忆成本的,get方式的缓存问题很蛋疼,尤其是低版本IE啦,废话少说, <scr ...

  7. java中数组是不是对象?

    [转自知乎]:http://www.zhihu.com/question/26297216 JAVA中的数组是对象吗? public class test { public static void m ...

  8. Oracle sqlloader

    一.SQL*LOADER简介 SQL*Loader是oracle提供的可以从多种平面文件中向数据库中加载数据的工具,使用sqlldr工具可以在很短的时间内向数据库中加载大量的数据,像把制作好的exce ...

  9. Hibernate基于【XML】和【注解】——完整实例

    Eclipse中新建Java Project工程: 工程结构  和  需要的Jar包: 我用的SqlServer数据库,所以连接数据库的Jar包是sqljdbc4.jar 一.基于XML配置 1.实体 ...

  10. SharePoint 2013的100个新功能之网站管理(一)

    一:设置盘 网站操作现在被替换为新的(设置)盘子.一些新的操作像添加一个应用.添加一个页面或设计管理器被添加而像创建网站则从菜单中移除了. 二:移除以其他用户身份登录 在SharePoint 2013 ...