2018.07.03 POJ 3348 Cows(凸包)
Cows
Time Limit: 2000MS Memory Limit: 65536K
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
Source
CCC 2007
很显然,这道题是要让我们算出给出点的凸包的面积。综上所述:这是一道凸包的裸板题,我本蒟蒻用的是Graham" role="presentation" style="position: relative;">GrahamGraham扫描法。
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 10005
using namespace std;
struct pot{
double x,y;
}p[N],vec[N];
inline double cross(pot a,pot b){return a.x*b.y-a.y*b.x;}
inline pot Vector(pot a,pot b){pot c;c.x=a.x-b.x,c.y=a.y-b.y;return c;}
inline double calc(pot *p,int n){
double ans=0;
for(int i=1;i<n-1;++i)
ans+=cross(Vector(p[i],p[0]),Vector(p[i+1],p[0]));
return ans/2;
}
inline bool cmp(const pot&x,const pot&y){return x.x==y.x?x.y<=y.y:x.x<y.x;}
inline int solve(pot *p,int n,pot *vec){
sort(p,p+n,cmp);
int m=0;
for(int i=0;i<n;++i){
while(m>1&&cross(Vector(vec[m-1],vec[m-2]),Vector(p[i],vec[m-2]))<=0)--m;
vec[m++]=p[i];
}
int k=m;
for(int i=n-2;i>=0;--i){
while(m>k&&cross(Vector(vec[m-1],vec[m-2]),Vector(p[i],vec[m-2]))<=0)--m;
vec[m++]=p[i];
}
if(n>1)m--;
return m;
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;++i)scanf("%lf%lf",&p[i].x,&p[i].y);
int m=solve(p,n,vec),ans=0;
double area=calc(vec,m);
while(area>=50)area-=50,++ans;
printf("%d",ans);
}
2018.07.03 POJ 3348 Cows(凸包)的更多相关文章
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- 2018.07.03 POJ 1279Art Gallery(半平面交)
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Description The art galleries of the new and ver ...
- 2018.07.08 POJ 2481 Cows(线段树)
Cows Time Limit: 3000MS Memory Limit: 65536K Description Farmer John's cows have discovered that the ...
- 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 [凸包 面积]
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9022 Accepted: 3992 Description ...
- POJ 3348 Cows | 凸包——童年的回忆(误)
想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...
- POJ 3348 Cows | 凸包模板题
题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...
随机推荐
- UI5-文档-4.34-Custom Controls
在这一步中,我们将使用自定义控件扩展SAPUI5的功能.我们希望对详细页面上显示的产品进行评级,因此我们使用SAPUI5扩展机制创建了多个标准控件的组合,并添加了一些粘合代码以使它们能够很好地一起工作 ...
- Jquery无缝轮播图的制作
轮播是html页面中比较常见的一种展现形式,也是基础,把轮播图做好,是排版中比较关键的 1.首先是轮播的html元素放置:做轮播之前,要有一个初步的认识 2.每个元素的位置怎样摆放,也是很关键的,这里 ...
- Haskell语言学习笔记(51)Comonad
Comonad class Functor w => Comonad w where extract :: w a -> a duplicate :: w a -> w (w a) ...
- adb连接过程中常见问题解决方法
在测试过程中经常会遇到需要使用adb连接服务器的问题,但是有时候经常会遇到连不上的情况,总结两种解决方式 1)error: unknown host service 此问题是由于端口号已经被占用了,可 ...
- jremoting的功能扩展点
1 InvokeFilter,实现此接口 可以在consumer端 与provider端的调用过程中拦截住请求调用. 已经实现的InvokeFilter包括 RetryInvokeFilter:实现 ...
- Nunit常用的方法说明
下来还是分为2个部分,一是NUnit的布局,另外一部分就是它的核心概念. 首先熟悉一下NUnit GUI的布局. 让我们更进一步看一下测试运行器窗口的布局.在右边面板的中间,可以看到测试进度条.进度条 ...
- pandas 语句
1.对于时间格式数据的处理 有些时候time_stamp是object格式,提取相应的日期,小时,星期等: 方法1 from datetime import datetime user_trad[ ...
- Linux就业技术指导(五):Linux运维核心管理命令详解
一,Linux核心进程管理命令 1.1 ps:查看进程 1.1.1 命令解释 功能说明 ps命令用于列出执行ps命令的那个时刻的进程快照,就像用手机给进程照了一张照片.如果想要动态地显示进程,就需要使 ...
- 基于JS的文本验证
1,不能为空 <input type="text" onblur="if(this.value.replace(/^ +| +$/g,'')=='')alert(' ...
- js ParseUrl
js ParseUrl function parseURL(url) { var a = document.createElement('a'); a.href = url; return { sou ...