poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 7038 | Accepted: 3242 |
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 yseparated 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
题意:题目的意思是给你n个点,让你用其中一些点围出最大面积,然后输出面积/50的下取整
思路:如果围出的多边形不是凸多边形,那么一定有凸多边形更优,所以求个凸包,计算凸包面积,/50取整
凸包算法:确定左下角的点,加入栈中,此后对于排过序的点,如果它到目前栈中最上面的两个点角度为钝角平角,那么它要比最上面那个点更优,弹出那个点,不断重复此操作,就能得到上凸包(因为点排过序,按照优先左的顺序,下凸包可能不完全),从第n-2点开始重复一遍此操作,得到下凸包
计算面积:左下角点一定是h[0],从左下角点连接所有到其他点的对角线,把原凸包分成很多个三角形,分别计算面积即可
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct pnt{
int x,y;
pnt(){x=y=0;}
pnt(int tx,int ty){x=tx;y=ty;}
pnt operator -(pnt p2){return pnt(x-p2.x,y-p2.y);}
pnt operator +(pnt p2){return pnt(x+p2.x,y+p2.y);}
bool operator <(pnt p2)const {if(x!=p2.x)return x<p2.x;return y<p2.y;}
bool operator >(pnt p2)const {if(x!=p2.x)return x>p2.x;return y>p2.y;}
bool operator ==(pnt p2)const {return x==p2.x&&y==p2.y;}
int dot(pnt p2){return x*p2.x+y*p2.y;}//点积
int det(pnt p2){return x*p2.y-y*p2.x;}//叉积
};
const int maxn=1e4+2;
pnt p[maxn],h[maxn];
int n,m;
void convexHull(){
sort(p,p+n);
m=0;
for(int i=0;i<n;i++){//计算上凸包
while(m>1&&(h[m-1]-h[m-2]).det(p[i]-h[m-2])<=0){m--;}
h[m++]=p[i];
}
int tm=m;
for(int i=n-2;i>=0;i--){//计算下凸包
while(m>tm&&(h[m-1]-h[m-2]).det(p[i]-h[m-2])<=0){m--;}
h[m++]=p[i];
}
if(n>1)m--;
}
double calArea(){
double ans=0;
for(int i=0;i<m;i++){
ans+=(double)((h[i]-h[0]).det(h[(i+1)%m]-h[0]))/2;//使用叉积计算面积
}
return ans;
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d%d",&p[i].x,&p[i].y);
convexHull();
int ans=(int)(calArea()/50.0);
printf("%d\n",ans);
return 0;
}
poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207的更多相关文章
- 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 ...
- POJ-3348 Cows 计算几何 求凸包 求多边形面积
题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...
- 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 | 凸包模板题
题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...
- POJ 3348 Cows | 凸包——童年的回忆(误)
想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- dp的简单递推笔记1
(1)转自rockZ的博文 UVa 10328 - Coin Toss (递推) 题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 原题中问出现连续至少k个H的情况,很难下手. ...
- Linux下修改时间
修改linux的时间可以使用date指令 date命令的功能是显示和设置系统日期和时间. 输入date 查看目前系统时间. 修改时间需要 date -功能字符 修改内容 命令中各选项的含义分别为: - ...
- quartz (二) Spring+Quartz实现定时任务的配置方法
JobDetail 设置执行的任务 :CronTrigger 触发器:设置执行的时间规则 ; Scheduler // 调度器,将任务与执行时间关联 本文转自:http://w ...
- 20145316《Java程序设计》实验一:Java开发环境的熟悉(Windows + IDEA)
20145316<Java程序设计>实验一:Java开发环境的熟悉(Windows + IDEA) 一.DOC命令行下Java程序开发 1.打开cmd,输入 mkdir 20145316命 ...
- Linux CentOS6环境下MySQL5.1升级至MySQL5.5版本过程
转载地址:http://www.laozuo.org/6145.html 老左今天有在帮朋友的博客搬迁到另外一台VPS主机环境,其环境采用的是LLSMP架构的,原先的服务器采用的是LNMP网站环境,其 ...
- 如何用纯 CSS 创作一个变色旋转动画
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/ejZWKL 可交互视频 ...
- tomcat和apache的区别
1. Apache是web服务器,Tomcat是应用(java)服务器(也可作web服务器),它只是一个servlet容器,是Apache的扩展. 2. Apache和Tomcat都可以做为独立的we ...
- java switch笔记
1. 在Java7之前,switch只能支持byte.short.char.int或者其对应的封装类以及Enum类型 2. Java7后,开始支持String 3. switch语句中,表达式的值不能 ...
- openwrt中如何在一个软件包中使能busybox中的工具
答:在软件包的Makefile中定义一个宏Package/package-name/config 举例:笔者自己制作了一个名为hello的软件包,但是这个软件包依赖busybox中的ifdown de ...
- CSS样式遇见的问题总结记录
一.子元素都是浮动元素时,父元素最好是不用设置高度,防止子元素不设置高度溢出父元素 有时候会有零点几的误差高度 直接设置子元素高度即可 通过 clear: both;清除子元素浮动达到父元素自适应高度 ...