题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N <= 100,  -1000 <= 坐标Xi, Yi <= 1000)。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4709

——>>面积最小,若有的话,一定是三角形。判断3点是否能组成一个三角形,若用斜率来做,麻烦且可能会有精度误差,用叉积来判断甚好(只需判断两向量的叉积是否为0)。

注意:N可为1、2,这时不能判断三角形。

#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; const int maxn = 100 + 10;
const double eps = 1e-10;
const double INF = 1 << 30; int N; struct Point{
double x;
double y;
Point(double x = 0, double y = 0):x(x), y(y){}
}p[maxn]; typedef Point Vector; Vector operator + (Point A, Point B){
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Point A, Point B){
return Vector(A.x - B.x, A.y - B.y);
} Vector operator * (Point A, double p){
return Vector(A.x * p, A.y * p);
} Vector operator / (Point A, double p){
return Vector(A.x / p, A.y / p);
} double Cross(Vector A, Vector B){
return A.x * B.y - B.x * A.y;
} double Area2(Point A, Point B, Point C){
return Cross(B-A, C-A);
} int dcmp(double x){
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
} void read(){
scanf("%d", &N);
for(int i = 0; i < N; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
} void solve(){
double Min = INF;
if(N >= 3){
for(int i = 0; i < N; i++)
for(int j = i+1; j < N; j++)
for(int k = j+1; k < N; k++) if(dcmp(Cross(p[j] - p[i], p[k] - p[i]))){
double temp = fabs(Area2(p[i], p[j], p[k]));
Min = min(Min, temp);
}
}
if(dcmp(Min - INF) == 0) puts("Impossible");
else printf("%.2f\n", Min/2);
} int main()
{
int T;
scanf("%d", &T);
while(T--){
read();
solve();
}
return 0;
}

hdu - 4709 - Herding的更多相关文章

  1. hdu 4709:Herding(叉积求三角形面积+枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  2. HDU 4709 Herding (枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  3. hdu 4709 Herding hdu 2013 热身赛

    题意:给出笛卡尔坐标系上 n 个点,n不大于100,求出这些点中能围出的最小面积. 可以肯定的是三个点围成的面积是最小的,然后就暴力枚举,计算任意三点围成的面积.刚开始是求出三边的长,然后求面积,运算 ...

  4. HDU 4709 Herding 几何题解

    求全部点组成的三角形最小的面积,0除外. 本题就枚举全部能够组成的三角形,然后保存最小的就是答案了.由于数据量非常少. 复习一下怎样求三角形面积.最简便的方法就是向量叉乘的知识了. 并且是二维向量叉乘 ...

  5. 学习数论 HDU 4709

    经过杭师大校赛的打击,明白了数学知识的重要性 开始学习数论,开始找题练手 Herding HDU - 4709 Little John is herding his father's cattles. ...

  6. HDU 4709:Herding

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  7. 【Herding HDU - 4709 】【数学(利用叉乘计算三角形面积)】

    题意:给出n个点的坐标,问取出其中任意点围成的区域的最小值! 很明显,找到一个合适的三角形即可. #include<iostream> #include<cstdio> #in ...

  8. HDU 4709 3-idiots FFT 多项式

    http://acm.hdu.edu.cn/showproblem.php?pid=4609 给一堆边,求这一堆边随便挑三个能组成三角形的概率. 裸fft,被垃圾题解坑了还以为很难. 最长的边的长度小 ...

  9. HDU Herding

    F - Herding Time Limit:1000MS       Memory Limit:32768KB      64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. Android消息机制不完全解析(上)

        Handler和Message是Android开发者常用的两个API,我一直对于它的内部实现比较好奇,所以用空闲的时间,阅读了一下他们的源码.    相关的Java Class: androi ...

  2. 多线程并发 synchronized对象锁的控制与优化

    本文针对用户取款时多线程并发情境,进行相关多线程控制与优化的描述. 首先建立用户类UserTest.业务操作类SynchronizedTest.数据存取类DataStore,多线程测试类MultiTh ...

  3. 在Eclipse中用SWT设计界面

    摘自http://www.tulaoshi.com/n/20160129/1488574.html 在Eclipse中用SWT设计界面 1. 为什么要使用SWT?  SWT是一个IBM开发的跨平台GU ...

  4. 关于MAC的pkg和mpkg的分别

    程序制作完毕后,在mac下通常的方法是要制作一个pkg的安装包,可是你会发现pkg和mpkg的文件出现的比較多,笔者也是经过了一定的试验和尝试,才了解到,pkg是单个文件的pkg,而mpkg事实上是多 ...

  5. Hyperion Essbase BusinessRule 函数学习--2

    @AVG Returns the average of all values in expList. [返回表达式列表的平均值] Syntax @AVG (SKIPNONE | SKIPMISSING ...

  6. 【巧妙消维DP】【HDU2059】龟兔赛跑

    龟兔赛跑 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  7. 新生赛(2) problem 2 丁磊养猪

    Problem B Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  8. 在美国公司架构中,LLC、LLP 和 Corporation 的区别何在?

    这个问题,首先需要弄清楚这样一个事实:LLC.LLP.Corporation分别属于三种不同类型的公司实体. 1,LLC (Limited Liability Company)是责任有限公司: 2,L ...

  9. C#创建Windows服务与安装-图解

    1.创建windows服务项目

  10. win7+IE11 中开发工具报错occurredJSLugin.3005解决办法

    系统环境 win7+IE11 报错描述: Exception in window.onload: Error: An error has ocurredJSPlugin.3005 Stack Trac ...