Herding

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1553 Accepted Submission(s):
440

Problem Description
Little John is herding his father's cattles. As a lazy
boy, he cannot tolerate chasing the cattles all the time to avoid unnecessary
omission. Luckily, he notice that there were N trees in the meadow numbered from
1 to N, and calculated their cartesian coordinates (Xi, Yi). To herding his
cattles safely, the easiest way is to connect some of the trees (with different
numbers, of course) with fences, and the close region they formed would be
herding area. Little John wants the area of this region to be as small as
possible, and it could not be zero, of course.
 
Input
The first line contains the number of test cases T(
T<=25 ). Following lines are the scenarios of each test case.
The first
line of each test case contains one integer N( 1<=N<=100 ). The following
N lines describe the coordinates of the trees. Each of these lines will contain
two float numbers Xi and Yi( -1000<=Xi, Yi<=1000 ) representing the
coordinates of the corresponding tree. The coordinates of the trees will not
coincide with each other.
 
Output
For each test case, please output one number rounded to
2 digits after the decimal point representing the area of the smallest region.
Or output "Impossible"(without quotations), if it do not exists such a
region.
 
Sample Input
1
4
-1.00 0.00
0.00 -3.00
2.00 0.00
2.00 2.00
 
Sample Output
2.00
 
 

题意:

告诉你很多个点的坐标,让你用这些点来求面积最小的三角形的面积。

套一个模版

通过三角形的顶点作坐标轴的平行线,把三角形围在一个矩形内,
该三角形的面积等于这个矩形面积减去两个直角三角形的面积
(三角形的一条边与坐标轴平行)或三个直角三角形的面积(三角形的边都
不与坐标轴平行),把式子写成行列式形式就得出这个公式了。

这样的,实际上用2阶就可以了(3阶那个写出来可以化成2阶)
比如有三个点(x1,y1),(x2,y2),(x3,y3)
那么用下面这个行列式
| x1-x3 y1-y3|
| x2-x3 y2-y3|
可以算一个值a出来
则S=1/2*|a|
记得一定要把a取绝对值
利用行列式的运算法则
S=(1/2)*(x1y2+x2y3+x3y1-y1x2-y2x3-y3x1)

假设空间三点A(x1,y1,z1) B(x2,y2,z2) C(x3,y3.z3) 那么S=1/2向量AB×向量BC

ps:http://acm.hdu.edu.cn/showproblem.php?pid=4709

转载请注明出处:http://www.cnblogs.com/yuyixingkong/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define maxn 1e10
using namespace std; struct point
{
double x,y;
}; double area(point a,point b,point c) //运用行列式求面积
{
double temp=((a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y));
return temp<? -temp:temp;//取绝对值;
}
int main()
{
double ans;
point p[];
int T,n,i,j,k;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
ans=maxn;
for(i=;i<n-;i++ )
{
for(j=i+;j<n-;j++)
{
for(k=j+;k<n;k++)
{
double temp=area(p[i],p[j],p[k])/2.0;
if(ans>temp&&temp>1e-)//精度控制
ans=temp;
}
}
}
if(n<||ans<1e-||ans==maxn)
printf("Impossible\n");
else
printf("%.2lf\n",ans);
}
return ;
}

Herding(hdu4709)三点运用行列式求面积的更多相关文章

  1. golang实现已知三角形三点坐标,求三角形面积

    代码如下: func GetTriangleAreaByVector(x vector.Vector3,y vector.Vector3,z vector.Vector3) float64 { //根 ...

  2. C语言:已知三角形三边长求面积

    //已知三角形三边长求面积 #include <stdio.h> #include <math.h> int main() { float a,b,c,p,s; int x=0 ...

  3. 两条线段求交点+叉积求面积 poj 1408

    题目链接:https://vjudge.net/problem/POJ-1408 题目是叫我们求出所有四边形里最大的那个的面积. 思路:因为这里只给了我们正方形四条边上的点,所以我们要先计算横竖线段两 ...

  4. 牛客训练二:处女座的签到题(STL+精度+三角形求面积公式)

    题目链接:传送门 知识点: (1)三个点,三角形求面积公式 (2)精度问题: double 15-16位(参考文章) float 6-7位 long long 约20位 int 约10位 unsign ...

  5. poj 3348--Cows(凸包求面积)

    链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:  ...

  6. P - Atlantis - hdu1542(求面积)

    题意:rt 求面积......不计算重复面积(废话..)hdu1255 的弱化版,应该先做这道题在做那道题的. ******************************************** ...

  7. 编写一个矩形类,私有数据成员为矩形的长( len)和宽(wid),wid设置为0,有参构造函数设置和的值,另外,类还包括矩形的周长、求面积、取矩形的长度、取矩形的长度、取矩形的宽度、修改矩形的长度和宽度为对应的形参值等公用方法。

    class Rectangle { private double len, wid; public Rectangle()//求矩形周长 { len = 0; wid = 0; } public Re ...

  8. 高斯消元与行列式求值 part1

    两道模板题,思路与算法却是相当经典. 先说最开始做的行列式求值,题目大致为给一个10*10的行列式,求其值 具体思路(一开始看到题我的思路): 1.暴算,把每种可能组合试一遍,求逆序数,做相应加减运算 ...

  9. HDU - 1255 覆盖的面积 (线段树求面积交)

    https://cn.vjudge.net/problem/HDU-1255 题意 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 分析 求面积并的题:https://www.cnbl ...

随机推荐

  1. 【Anaconda】:科学计算的Python发行版

    [背景] Python易用,但包管理和Python不同版本的问题比较头疼,特别是当你使用Windows的时候.为了解决这些问题,有不少发行版的Python,比如WinPython.Anaconda等, ...

  2. Mysql数据优化--DBA梳理珍藏篇

    1. 优化SQL 1)     通过show status了解各种sql的执行频率 show status like 'Com_%'        了解 Com_select,Com_insert 的 ...

  3. 【xsy2193】Wallace 最大权闭合子图

    题目大意:给你一棵$n$个节点的树$a$,每个点有一个点权$val_i$,同时给你另一棵$n$个节点的树$b$. 现在你需要在树$a$上找一个联通块,满足这些点在树$b$上也是连通的,同时树$a$的这 ...

  4. JS 在页面上直接将json数据导出到excel,支持chrome,edge,IE10+,IE9,IE8,Safari,Firefox

    JS 在页面上直接将json数据导出到excel,支持chrome,edge,IE10+,IE9,IE8,Safari,Firefox <html> <head> </h ...

  5. MySQL笔记(1)---MySQL体系结构和存储引擎

    1.前言 本系列记录MYSQL数据库的一些结构和实现特点,方便查询. 2.基本概念 数据库:物理操作系统文件或者其他形式文件类型的集合.MySQL中数据库文件可以是frm.MYD.MYI.ibd结尾的 ...

  6. ASP.NET Core 1.0 中 EntityFramework 与 PostgreSQL 的使用

    https://docs.efproject.net/en/latest/providers/npgsql/index.html 前面在CentOS6.7环境下配置好了PostgreSQL, 就顺便试 ...

  7. RocketMq(二)消息中间件源码下载、模块分化以及集群模式的认知

    1.通过IDEA使用git下载源码 到RocketMq官网指定的GitHub路径获取下载链接 https://github.com/apache/rocketmq 获取下载源码路径 使用IDEA自带的 ...

  8. RocketMq(一)初识消息中间件

    1.对消息的理解 消息即为数据(data),数据有一定的规则.长度.大小. Java Message Service(Java消息服务)简称JMS,为Java 程序提供一种通用的方式,来创建.发送.接 ...

  9. 微信小程序网络封装-简单高效

    废话引言 小程序虽然出世很久了,但一直没怎么接触到小程序开发.吉他兴趣班老师想弄一个小程序发布课程信息和打卡功能,作为IT一员就自愿加入了这个小程序开发小组中.虽然小程序面向的是前端工程师,但作为移动 ...

  10. Nhibernate + MySQL 类型映射

    用SQLyog工具创建表 然后用自动映射工具NHibernate Mapping Generator对表做自动映射,得到 这个是可视化界面,后面有对应的代码. using System; using ...