HDU - 4709 Herding

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 

Source

2013 ACM/ICPC Asia Regional Online ―― Warmup

思路: 枚举计算

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 150;
const double INF = 100000000.0;

struct node {
	double x, y;
} point[MAXN];
int n;

double dis(int a, int b) {
	return sqrt((point[a].x-point[b].x)*(point[a].x-point[b].x)+(point[a].y-point[b].y)*(point[a].y-point[b].y));
}

double cal(int a, int b, int c) {
	double A = dis(a, b);
	double B = dis(a, c);
	double C = dis(b, c);
	double p = (A+B+C)/2;
	return sqrt(p*(p-A)*(p-B)*(p-C));
}

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (int i = 0; i < n; i++)
			scanf("%lf%lf", &point[i].x, &point[i].y);
		double ans = 1e20;
		int flag = 0;
		for (int i = 0; i < n; i++)
			for (int j = i+1; j < n; j++)
				for (int k = j+1; k < n; k++) {
					double tmp = cal(i, j, k);
					if (fabs(tmp) >= 0.01) {
						flag = 1;
						ans = min(ans, tmp);
					}
				}
		if (!flag)
			printf("Impossible\n");
		else printf("%.2lf\n", ans);
	}
}
时间: 2024-10-30 10:25:55

HDU - 4709 Herding的相关文章

HDU 4709 Herding 几何题解

求所有点组成的三角形最小的面积,0除外. 本题就枚举所有可以组成的三角形,然后保存最小的就是答案了,因为数据量很少. 复习一下如何求三角形面积.最简便的方法就是向量叉乘的知识了. 而且是二维向量叉乘P1(ax, ay), P2(bx, by),公式为:|P1 X P2| = abs(ax*by - ay*bx) 三角形面积就是|P1 X P2| / 2; 本题也是float过不了,换成double就可以过了. const int MAX_N = 101; struct VertexPoint {

hdu 4709 Herding (数学)

///给你n个点 枚举三点求最小三角形面积 # include <algorithm> # include <stdio.h> # include <string.h> # include <iostream> # include <math.h> # include <string> using namespace std; int main() { int t,n,i,j,k; double x[110],y[110],minn,

hdu 4709

求三角形的面积 利用向量点乘得到三角形的面积 三个for循环嵌套即可 #include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; const double INF = 1e9+50; double x[1000]; double y[1000]; double area(int i, int j, int k) { double ax

模拟2

    ID Origin Title 6 / 10 Problem A HDU 4706 Children's Day 7 / 22 Problem B HDU 4707 Pet 5 / 25 Problem C HDU 4708 Rotation Lock Puzzle 6 / 26 Problem D HDU 4709 Herding 1 / 9 Problem E HDU 4710 Balls Rearrangement     Problem F HDU 4711 Weather  

HDU Herding

F - Herding Time Limit:1000MS       Memory Limit:32768KB      64bit IO Format:%I64d & %I64u Submit Status 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

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 t

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include

hdu 1207 汉诺塔II (DP+递推)

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往