poj 3348 Cow 凸包面积
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 8122 | Accepted: 3674 |
Description
Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.
However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.
Input
The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).
Output
You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.
Sample Input
4
0 0
0 101
75 0
75 101
Sample Output
151
/*
poj 3348 Cow 凸包面积 给你n棵树绕成一个圈,问最多可以养多少牛
用所有点求出凸包然后求出多边形的面积即可 hhh-2016-05-08 18:47:21
*/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
using namespace std;
const int maxn = 10100;
double PI = 3.1415926;
double eps = 1e-8; int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0)
return -1;
else
return 1;
} struct Point
{
double x,y;
Point() {}
Point(double _x,double _y)
{
x = _x,y = _y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
}; struct Line
{
Point s,t;
Line() {}
Line(Point _s,Point _t)
{
s = _s;
t = _t;
}
pair<int,Point> operator &(const Line&b)const
{
Point res = s;
if( sgn((s-t) ^ (b.s-b.t)) == 0) //通过叉积判断
{
if( sgn((s-b.t) ^ (b.s-b.t)) == 0)
return make_pair(0,res);
else
return make_pair(1,res);
}
double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t));
res.x += (t.x-s.x)*ta;
res.y += (t.y-s.y)*ta;
return make_pair(2,res);
}
};
Point lis[maxn];
int Stack[maxn],top; double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
bool cmp(Point a,Point b)
{
double t = (a-lis[0])^(b-lis[0]);
if(sgn(t) == 0)
{
return dist(a,lis[0]) <= dist(b,lis[0]);
}
if(sgn(t) < 0)
return false;
else
return true;
} bool Cross(Point a,Point b,Point c)
{
return (b.y-a.y)*(c.x-b.x) == (c.y-b.y)*(b.x-a.x);
} void Graham(int n)
{
Point p; int k = 0;
p = lis[0];
for(int i = 1; i < n; i++)
{
if(p.y > lis[i].y || (p.y == lis[i].y && p.x > lis[i].x))
p = lis[i],k = i;
}
swap(lis[0],lis[k]);
sort(lis+1,lis+n,cmp);
if(n == 1)
{
top = 1;
Stack[0] = 0;
return ;
}
if(n == 2)
{
Stack[0] = 0,Stack[1] = 1;
top = 2;
return;
}
Stack[0] = 0;
Stack[1] = 1;
top = 2;
for(int i = 2; i < n; i++)
{
while(top > 1 && sgn((lis[Stack[top-1]]-lis[Stack[top-2]])
^ (lis[i]-lis[Stack[top-2]])) <= 0)
top --;
Stack[top++] = i;
}
} int main()
{
//freopen("in.txt","r",stdin);
int n;
while(scanf("%d",&n) != EOF)
{
for(int i = 0; i < n; i++)
{
scanf("%lf%lf",&lis[i].x,&lis[i].y);
}
Graham(n); double res = 0;
for(int i = 0;i < top;i++)
{
res += (lis[Stack[i]]^lis[Stack[(i+1)%top]])/2;
}
int ans = res;
printf("%d\n",ans/50);
}
return 0;
}
poj 3348 Cow 凸包面积的更多相关文章
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- POJ 3348 Cows [凸包 面积]
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9022 Accepted: 3992 Description ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- POJ 3348 Cows (凸包模板+凸包面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- POJ 3348 Cows | 凸包模板题
题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...
- POJ 3348 Cows | 凸包——童年的回忆(误)
想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...
- POJ 1654 Area 凸包面积
水题直接码... /********************* Template ************************/ #include <set> #include < ...
- poj 3348:Cows(计算几何,求凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6199 Accepted: 2822 Description ...
随机推荐
- 201621123057 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...
- zookeeper安装及环境变量设置
下载 首先去官网下载(自行选择版本):http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.11/然后执行tar -zxvf解压 对于后台安装 ...
- 织梦cms网上复制图片不可用的解决方法
背景描述: 织梦cms采集图片集时, 需要使用织梦cms提供的"网上复制图片"的功能, 好像我这里这个功能一直不可用, 今天下定决心研究了下源代码并进行了适当修改, 将我的修改提供 ...
- vue初尝试--项目结构
新建一个项目之后,我们来看一下项目的目录结构 几个主要文件的内容 index.html文件(入口文件,系统进入之后先进入index.html) <!DOCTYPE html> <ht ...
- linux cenots7安装mysql
1.下载mysql 下载的话先确认好版本. system:centos7 mysql:5.7 下面的版本自己选择,一般是86位的. 下载好的文件 2.上传到服务器 soft文件夹,终端也进入了 ...
- java希尔排序
java希尔排序 1.基本思想: 希尔排序也成为"缩小增量排序",其基本原理是,现将待排序的数组元素分成多个子序列,使得每个子序列的元素个数相对较少,然后对各个子序列分别进行直接插 ...
- Nagios监控的部署与配置
[安装Nagios] yum install -y httpd httpd-devel httpd-tools mysql mysql-devel mysql-server php php-devel ...
- SpringBoot单元测试中的测试方法执行顺序
一.忽略方法@ignore 二.执行顺序@FixMethodOrder(MethodSorter.JVM) 我们在执行JUnit测试用例时,有时需要按照定义顺序执行单元测试方法,比如如在测试数据库相关 ...
- OAuth2.0学习(1-12)开源的OAuth2.0项目和比较
OAuth2.0学习(2-1)OAuth的开源项目 1.开源项目列表 http://www.oschina.net/project/tag/307/oauth?lang=19&sort=t ...
- python爬虫requests的使用
1 发送get请求获取页面 import requests # 1 要爬取的页面地址 url = 'http://www.baidu.com' # 2 发送get请求 拿到响应 response = ...