Herding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1902 Accepted Submission(s): 540
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.
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.
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.
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <queue>
- #include <set>
- #include <stack>
- #include <cstring>
- #include <cmath>
- #include <iostream>
- #define INF 1 << 25
- #define eps 1e-8
- using namespace std;
- struct node{
- double x,y;
- }a[];
- int n;
- int check(node a,node b,node c)//向量判断是否3点在同一直线
- {
- node v1, v2;
- v1.x = a.x - b.x;
- v1.y = a.y - b.y;
- v2.x = c.x - b.x;
- v2.y = c.y - b.y;
- if(fabs(v1.x * v2.y - v2.x * v1.y) < eps ) return ;
- else return ;
- }
- double calc(node a,node b,node c)//求面积
- {
- double res = ;
- res = fabs(a.x * b.y + b.x * c.y + c.x * a.y - b.x * a.y - c.x * b.y - a.x * c.y);
- return res/2.0;
- }
- void solve()
- {
- scanf("%d",&n);
- for(int i = ; i <=n ; ++i)
- scanf("%lf%lf",&a[i].x,&a[i].y);
- if(n == || n == ) { printf("Impossible\n"); return; }
- double ans = INF;
- for(int i = ; i <= n ;++i)//暴力枚举
- for(int j = i + ; j <=n ; ++j)
- for(int k = j + ; k <= n ; ++k)
- if(check(a[i],a[j],a[k])){
- double now = calc(a[i],a[j],a[k]);
- if(now < ans) ans = now;
- }
- // cout << ans <<endl;
- if(ans != INF)
- printf("%.2f\n",ans);
- else printf("Impossible\n");
- }
- int main()
- {
- ios::sync_with_stdio();
- int t;
- scanf("%d",&t);
- while(t--)
- solve();
- return ;
- }
Herding的更多相关文章
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- HDU 4709:Herding
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU Herding
F - Herding Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- Herding(hdu4709)三点运用行列式求面积
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 4709 Herding (枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDUOJ---(4708)Herding
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- hdu 4709:Herding(叉积求三角形面积+枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu - 4709 - Herding
题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N < ...
- hdu 4709 Herding hdu 2013 热身赛
题意:给出笛卡尔坐标系上 n 个点,n不大于100,求出这些点中能围出的最小面积. 可以肯定的是三个点围成的面积是最小的,然后就暴力枚举,计算任意三点围成的面积.刚开始是求出三边的长,然后求面积,运算 ...
随机推荐
- 安装Django,运行django-admin.py startproject 工程名,后不出现指定的工程解决办法!!
第一次写博客,,,,, 在看我这篇教程的前提是你应该已经正确装好python和Django了,好了,废话不说了,正题走你!你现在是不是很纠结自己运行django-admin.py startpr ...
- 带你熟悉CSS浮动
一.概念理解 浮动:顾名思义先浮后动,浮动的对象会先漂浮起来,离开自己原来的位置(也就是所谓的脱离文档流),后动的意思是,它的后面的元素会向它原来的位置动起来. 二.注意事项 1.当元素有浮动属性时, ...
- August 20th 2016 Week 34th Saturday
Everything you see exists together in a delicate balance. 你所看到的一切都处于微妙的平衡中. Seeking for balance in l ...
- Mysql之performance Schema
Performance schema是用于监控Mysql执行,具有如下特征: 1.用于在运行时探查Mysql Server的执行过程,是由Performance_schema引擎和 Performan ...
- 2 配置Ionic开发环境以及创建新的项目
1.开发环境需要的软件有: node.js http://nodejs.org 可以到官方网站下载对应平台的安装包安装即可,如果已经安装,需要把它升级到最新的稳定版本 在终端可以输入$node ...
- (转)ORA-12519: TNS:no appropriate service handler found 的问题处理。
很多时候出现:ORA-12519: TNS:no appropriate service handler found 都是由于当前的连接数已经超出他能够处理的最大值了. 处理方法如下:摘自网上. se ...
- javascript 面向对象编程小记
虽然平常用jquery用的很熟,但是基本都是面向过程的写法.一个事件一个function,很少有面向对象的写法.今天得写一个日期控件,不得不用上面向对象编程. 刚开始我的想法是: var datepi ...
- struts标签<logic:iterate>的用法
<logic:iterate>主要用来处理在页面上输出集合类,集合一般来说是下列之一: 1. java对象的数组 2. ArrayList.Vector.HashMap等 具体用法请参考s ...
- 游戏主循环(Game Loop)
游戏主循环是游戏的心跳,一般使用while循环进行主动刷新. 一次循环由获取用户输入.更新游戏状态.处理AI.播放音乐和绘制画面组成. 这些行为可以分成两类: update_game(); // 更新 ...
- NBU bplabel命令擦除磁帶數據
bplabel Linux系統,該命令位於NBU server的如下目錄:/usr/openv/netbackup/bin/admincmd bplabel – write NetBackup lab ...