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. ViewPager无限滑动

    2016-6-19 前言 View轮播效果在app中很常见,一想到左右滑动的效果就很容易想到使用ViewPager来实现.对于像我们常说的banner这样的效果,具备无限滑动的功能是可以用ViewPa ...

  2. 【CF600E】 Lomsat gelral

    CF600E Lomsat gelral Solution 考虑一下子树的问题,我们可以把一棵树的dfn序搞出来,那么子树就是序列上的一段连续的区间. 然后就可以莫队飞速求解了. 但是这题还有\(\T ...

  3. js判断是否手机自动跳转移动端

    写法一: {literal} <script> //判断是否手机自动跳转 var browser={versions:function(){var u=navigator.userAgen ...

  4. Code Chef April Cook-Off 2019题解

    传送门 \(PEWDSVTS\) 我哪根筋不对了要把所有可行的拿出来\(sort\)一下--还有忘开\(long\ long\)真的好难受-- int main(){ // freopen(" ...

  5. Class和普通js构造函数的区别

    Class 在语法上更加贴合面向对象的写法 Class 实现继承更加易读.易理解 更易于写 java 等后端语言的使用 本质还是语法糖,使用 prototype Class语法 typeof Math ...

  6. iOS开发-实现相机app的方法[转载自官方]

    This brief code example to illustrates how you can capture video and convert the frames you get to U ...

  7. 利用Makefile安装helloworld模块(速成)

    这学期对了一门操作系统,满怀着好奇装了虚拟机然后安了Ubuntu,这周作业是编译内核和安装个模块,妈耶,折腾了我一两天.终于弄完,CSDN上有挺多类似的教程,例如陈皓的跟我一起写Makefile,写的 ...

  8. 在matlab中实现梯度下降法

    梯度下降法的原理,本文不再描述,请参阅其它资料. 梯度下降法函数function [k ender]=steepest(f,x,e),需要三个参数f.x和e,其中f为目标函数,x为初始点,e为终止误差 ...

  9. JVM中强引用,弱引用,软引用和幽灵引用的代码

    上代码: public class ReferenceTest { public static void main(String[] args) { //test1();//软引用 //test2() ...

  10. android开发学习——day6

    关于UI的几个插件学习 button和textview,以及点击button利用Toast提醒,editText private EditText editText; @Override protec ...