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. DataGrid列表信息保存为EXCEL到指定的路径 ---------继续DataGrid在WPF的数据绑定

    一.许多WPF或者Winform程序在保存数据时,会以EXCEL或者文本的形式展现可视化界面的数据,本文就简单介绍下将DataGrid列表信息保存为EXCEL到指定的路径下,例子很简单,用的着的直接用 ...

  2. java之Collection框架

    Collection的一些框架类的关系图: 1 Collection简介 Collection的定义 public interface Collection<E> extends Iter ...

  3. JQuery 限制文本输入只能输入数字(可自定义正则表达式)

    var JVerify = { role: { number: /[0-9\/]/, decimal: /[0-9\.\/]/, code: /[0-9A-Z]/ }, Verify: functio ...

  4. Windows Phone开发手记-WinRT下分组拼音的实现

    Windows Phone版本号自升入8.1以来,开发者就多了一个选项,开发基于WinRT架构的WP或者Universal Windows App.然而开发框架转为WinRT后,很多原有的WP8基于S ...

  5. 几种int类型的范围

    我们在编程的过程经常会遇到数据溢出的情况,于是这个时候我们必须定义能表示更大的数的数据类型来表示这个数. 下面列出了int型的范围: unsigned   int   0-4294967295    ...

  6. java和js获取当前天之后或之前7天(任意)日期

    一.获取过去第几天的日期(- 操作) 或者 未来 第几天的日期( + 操作) /** * 获取过去第几天的日期(- 操作) 或者 未来 第几天的日期( + 操作) * * @param past * ...

  7. (转) JVM Crash with SIGSEGV - problematic frame - libzip.so

    原文:https://stackoverflow.com/questions/38057362/jvm-crash-with-sigsegv-problematic-frame-libzip-so h ...

  8. 基于.Net + SqlServer的分库分表设计方案

    在说分库分表之前,先简单介绍下网站架构,这样有助于理解为何需要分库分表这种技术.因为所有的技术,大多都是因为业务的需要而产生的. 1.网站发展的第一阶段 大致架构如下,因为没有多少用户访问,所以单台服 ...

  9. Android使用内容提供者实现增删改查操作

    Android使用内容提供者实现增删改查操作 这里需要建立两个项目:SiYouShuJuKu(使用内容提供者暴露相关的操作),DQDYGApplication(使用内容解析者对第一个应用进行相关的解析 ...

  10. 关于Python数据分析与机器学习的一些资源

    https://github.com/search?l=Python&o=desc&q=python&s=stars&type=Repositories&utf ...