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 ...
随机推荐
- GitChat招募IT类写作作者
GitChat是一个移动端的IT知识.技术分享平台,于2017.10和CSDN合并,成为其旗下独立品牌. 我们正在寻求有互联网基因的人来一起分享IT人员的关切,诚挚邀请您来做一次分享(让IT类文章变现 ...
- Python struct模块
有的时候需要用python处理二进制数据,比如,存取文件,socket操作时.这时候,可以使用python的struct模块来完成.可以用 struct来处理c语言中的结构体. struct模块中最重 ...
- [2]十道算法题【Java实现】
前言 清明不小心就拖了两天没更了-- 这是十道算法题的第二篇了-上一篇回顾:十道简单算法题 最近在回顾以前使用C写过的数据结构和算法的东西,发现自己的算法和数据结构是真的薄弱,现在用Java改写一下, ...
- WPF自定义控件与样式-自定义按钮(Button)
一.前言 程序界面上的按钮多种多样,常用的就这几种:普通按钮.图标按钮.文字按钮.图片文字混合按钮.本文章记录了不同样式类型的按钮实现方法. 二.固定样式的按钮 固定样式的按钮一般在临时使用时或程序的 ...
- 微信接口(一)创建菜单&自动回复
刚划拉完微信.做一个笔记这里的数据是写死的,还有一份是通过查询数据库进行自动回复,自定义菜单设置的.不过因为使用到数据库,最好在网站后台吧微信平台开发集成进去.所以代码较多就先不放了.有问题的地方请留 ...
- api-gateway实践(08)新服务网关 - 云端发布和日志查看
一.发布应用 1.新建应用空间 1.1.新建应用空间 1.2.新建应用 1.3.上传程序包 2.创建应用引擎服务 3.发布应用 3.1.为应用容器绑定Web运行环境(应用引擎服务) 3.2.发布应用( ...
- intelj idea中JRebel激活
1.下载激活软件 https://github.com/ilanyu/ReverseProxy/releases/tag/v1.0 我这边下载的是: 2.双击运行 3.idea中, 不出意外,应该就激 ...
- nginx反向代理二级域名注意事项
摘要 本文介绍了利用nginx实现多域名和多站点的绑定的方法及相关注意事项.您也可以只看本文的标题或红色标注部分.☺ 1.应用场景 我们经常会遇到在同一台服务器建立多个Web站点的情况,普遍的做法是为 ...
- python/零起点(一、列表)
python/零起点(一.列表) 列表(list)list()可以强行转换数据类型为列表,列表是可迭代对象 列表是有序的,且列表是可变的数据类型 列表中的元素可以是(字符串.整型.元祖.列表.字典.集 ...
- python基础——面向对象进阶下
python基础--面向对象进阶下 1 __setitem__,__getitem,__delitem__ 把对象操作属性模拟成字典的格式 想对比__getattr__(), __setattr__( ...