Herding(hdu4709)三点运用行列式求面积

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<0? -temp:temp;//取绝对值;
}
int main()
{
    double ans;
    point p[105];
    int T,n,i,j,k;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        ans=maxn;
        for(i=0;i<n-2;i++ )
        {
            for(j=i+1;j<n-1;j++)
            {
                for(k=j+1;k<n;k++)
                {
                    double temp=area(p[i],p[j],p[k])/2.0;
                    if(ans>temp&&temp>1e-8)//精度控制
                        ans=temp;
                }
            }
        }
        if(n<3||ans<1e-4||ans==maxn)
            printf("Impossible\n");
        else
            printf("%.2lf\n",ans);
    }
    return 0;
}

Herding(hdu4709)三点运用行列式求面积

时间: 2024-09-29 02:04:54

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

POJ 2954 Triangle (皮克定理, 三角形叉乘求面积)

Triangle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5303 Accepted: 2297 Description A lattice point is an ordered pair (x, y) where x and y are both integers. Given the coordinates of the vertices of a triangle (which happen to be lat

poj 1654 Area (多边形求面积)

链接:http://poj.org/problem?id=1654 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14952   Accepted: 4189 Description You are going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orth

实验12:Problem B: 图形计数与求面积

注意构造函数中的数据类型是double类型,如果定义成int会出错,而且一旦出错很不容易发现这个错误 Home Web Board ProblemSet Standing Status Statistics Problem B: 图形计数与求面积 Problem B: 图形计数与求面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 563  Solved: 360[Submit][Status][Web Board] Description 定义三

hdu 1542 Atlantis 线段树求面积并,,,尼玛数据真坑人,数组千万不能开小!

Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7815    Accepted Submission(s): 3420 Problem Description There are several ancient Greek texts that contain descriptions of the fabled i

Scala实现:已知三点坐标,求最短距离(如果在垂足不在线段内,最短距离为到其中一点的直线距离)

/** * 已知三点坐标,求其中一点到另两点的垂线距离 * (如果在垂足不在线段内,最短距离为到其中一点的直线距离) * Created by wzq on 17-11-2. */object Point2lineDistance { def main(args: Array[String]) { val v: Double = pointToLine(-3, 0, 3, 0, 0, 3) System.out.println(v) } def pointToLine(x1: Int, y1:

【POJ 1408】 Fishnet (叉积求面积)

[POJ 1408] Fishnet (叉积求面积) 一个1*1㎡的池塘 有2*n条线代表渔网 问这些网中围出来的最大面积 一个有效面积是相邻两行和相邻两列中间夹的四边形 Input为n 后面跟着四行 每行n个浮点数 每一行分别代表a,b,c,d 如图 并且保证a(i) > a(i-1) b(i) > b(i-1) c(i) > c(i-1) d(i) > d(i-1) n(n <= 30)*2+4(四个岸)条边 枚举点数就行 相邻的四个四个点枚举 找出围出的最大面积 找点用

poj 1265 Area (Pick定理+求面积)

链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4969   Accepted: 2231 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionag

uva 10065 (凸包+求面积)

链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=1006 Problem A Useless Tile Packers Input: standard input Output: standard output Yes, as you have apprehended the Useless Tile Pac

zoj 1010 (线段相交判断+多边形求面积)

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Jerry, a middle school student, addicts himself to mathematical research. Maybe the problems he has thought are