HDU 4709 Herding
来源:互联网 发布:数据库自定义函数 编辑:程序博客网 时间:2024/05/27 08:13
Herding
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
14-1.00 0.000.00 -3.002.00 0.002.00 2.00
Sample Output
2.00
题意:给出你n个点的坐标,让你求出任意几个点围成的最小面积
分析:既然叫求围成的最小面积,最先想到是三角形的面积,因为任意的多边形都可以分成三角形
分析:既然叫求围成的最小面积,最先想到是三角形的面积,因为任意的多边形都可以分成三角形
给出三点坐标求三角形的面积
设A(x1,y1),B(x2,y2),C(x3,y3) 由A-->B-->C-->A 按逆时针方向转。(行列式书写要求) 设三角形的面积为S 则S=(1/2)*(下面行列式) |x1 y1 1| |x2 y2 1| |x3 y3 1| S=(1/2)*(x1y2*1+x2y3*1+x3y1*1-x1y3*1-x2y1*1-x3y2*1) 即用三角形的三个顶点坐标求其面积的公式为: S=(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2)于是枚举出所有的求出最小即可。
#include<stdio.h>#include<math.h>int main(){ int t; scanf("%d",&t); while(t--) { int n,i,j,k; double a[105],b[105],min=9999999,s = -1; scanf("%d",&n); for(i = 1 ; i <= n ; i ++) scanf("%lf%lf",&a[i],&b[i]); if(n <= 2) //小于3说明围不成三角形 { printf("Impossible\n"); continue; } else { for(i = 1 ; i <= n-2 ; i ++) //求出所有的三角形面积,求出最小 for(j = i+1 ; j <= n-1 ; j ++) for(k = j+1 ; k <= n ; k ++) { s =fabs( 0.5*(a[i]*b[j]-a[j]*b[i]+a[j]*b[k]-a[k]*b[j]+a[k]*b[i]-a[i]*b[k])); if(s!=0&&s < min) min = s; } } if(min==9999999) printf("Impossible\n"); else printf("%.2lf\n",min); } return 0;}
0 0
- hdu 4709 Herding
- hdu 4709 Herding acm
- hdu - 4709 - Herding
- HDU 4709 Herding
- hdu 4709 Herding
- HDU 4709 Herding
- HDU 4709 Herding
- HDU - 4709 Herding
- HDU 4709 Herding
- hdu 4709 Herding (数学)
- HDU 4709 Herding
- HDU 4709 Herding
- HDU 4709 Herding
- hdu 4709 Herding
- HDU 4709:Herding
- HDU 4709 Herding
- hdu 4709 Herding
- hdu 4709 Herding
- 【leetcode】 260. Single Number III
- 变量关系探索
- (Paper)Robust Text Detection in Natural Scene Images
- appium在使用uiautomatorviewer.bat获得页面元素的使用方法
- P1117 拯救ice-cream tyvj
- HDU 4709 Herding
- iOS 用Applicaton Loader提交ipa到iTunes Connect ——iOS上线相关(二)
- 玩转Android studio 插件开发、测试、JCenter库发布(4)
- block循环引用问题
- Python项目之即时标记
- H.264码流与帧结构
- 在Quartz工作中添加监听器
- 堆排序
- 【Swift】反射(Reflection)的介绍