poj 3348:Cows(计算几何,求凸包面积)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 6199 | Accepted: 2822 |
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
#include <iostream>
#include <iomanip>
#include <cmath>
#include <stdio.h>
using namespace std; struct Point{
double x,y;
};
double dis(Point p1,Point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double xmulti(Point p1,Point p2,Point p0) //求p1p0和p2p0的叉积,如果大于0,则p1在p2的顺时针方向
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int graham(Point p[],int n,int pl[]) //求凸包,返回凸包中点的个数+1
{
//找到纵坐标(y)最小的那个点,作第一个点
int i;
int t = ;
for(i=;i<=n;i++)
if(p[i].y < p[t].y)
t = i;
pl[] = t;
//顺时针找到凸包点的顺序,记录在 int pl[]
int num = ; //凸包点的数量
do{ //已确定凸包上num个点
num++; //该确定第 num+1 个点了
t = pl[num-]+;
if(t>n) t = ;
for(int i=;i<=n;i++){ //核心代码。根据叉积确定凸包下一个点。
double x = xmulti(p[i],p[t],p[pl[num-]]);
if(x<) t = i;
}
pl[num] = t;
} while(pl[num]!=pl[]);
return num-;
}
double getS(Point a,Point b,Point c) //返回三角形面积
{
return ((b.x - a.x) * (c.y - a.y) - (b.y - a.y)*(c.x - a.x))/;
}
double getPS(Point p[],int pl[],int n) //返回多边形面积。必须确保 n>=3,且多边形是凸多边形
{
double sumS=;
for(int i=;i<=n-;i++)
sumS+=fabs(getS(p[pl[]],p[pl[i]],p[pl[i+]]));
return sumS;
}
int main()
{
int n;
while(cin>>n){
Point p[];
int pl[];
int i;
for(i=;i<=n;i++) //输入点
scanf("%lf%lf",&p[i].x,&p[i].y);
int num = graham(p,n,pl); //求凸包,并返回凸包点个数
printf("%d\n",int(getPS(p,pl,num)/)); //求凸包面积
}
return ;
}
Freecode : www.cnblogs.com/yym2013
poj 3348:Cows(计算几何,求凸包面积)的更多相关文章
- POJ-3348 Cows 计算几何 求凸包 求多边形面积
题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- 【UVA10652】Board Wrapping(求凸包面积)
点此看题面 大致题意: 告诉你若干个矩形的重心坐标.长.宽和相对\(y\)轴的偏转角度,求矩形面积和与能围住这些矩形的最小凸包面积之比. 矩形面积和 这应该是比较好求的吧. 已经给了你长和宽,直接乘起 ...
- poj3348(求凸包面积)
题目链接:https://vjudge.net/problem/POJ-3348 题意:转换题意后即是求凸包的面积. 思路: 套模板,求凸包面积即转换为多个三角形面积之和,用叉积求,然后除2,因为本题 ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj 3348 Cows 求凸包面积
题目链接 大意: 求凸包的面积. #include <iostream> #include <vector> #include <cstdio> #include ...
- POJ 3348 Cows(凸包+多边形面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- POJ 3348 Cows (凸包模板+凸包面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
随机推荐
- How to add a button in the seletions "More"
<?xml version="1.0" encoding="utf-8"?> <openerp> <data> <re ...
- 4种常见的MySQL日志类型
4种常见的MySQL日志类型 .错误日志 记录启动.运行或停止mysqld时出现的问题 log-error=d:/mysql_log_err.txt .查询日志 记录建立的客户端连接和执行的所有语句( ...
- OFBiz:添加样式【转】
原文地址:http://www.cnblogs.com/ofbiz/p/3205851.html 1. 打开themes文件夹,拷贝一份样式作为自己的样式更改初始样式,我这里拷贝的是flatgrey文 ...
- 【NEWS】 ADempiere发布ADempiere 3.8.0路线图【2013年7月28日】
发布源:http://osssme.org/cms/?q=node/17 本以为ADempiere”已死“,但是看到ADempiere的WIKI上大概在从5月28日开始添加WIKI以来,经过多次更新后 ...
- spring.xml从外部文件引入数据库配置信息
<!-- 分散配置 --> <context:property-placeholder location="classpath:jdbc.properties" ...
- LaTeX去掉默认显示日期时间
LaTeX去掉默认显示日期时间: \date{}
- 在ASP.Net和IIS中删除不必要的HTTP响应头[转]
http://www.cnblogs.com/CareySon/archive/2009/12/14/1623624.html 引入 每次当浏览器向Web服务器发起一个请求的时,都会伴随着一些HTTP ...
- 打开office提示还有几天过期的处理办法
是多重激活了,把激活码失效的删除即可 1.以管理员权限打开cmd(必须以管理员权限,不然无法删除无效的激活码) 2.输入命令:cd C:\Program Files (x86)\Microsoft O ...
- unity5, 在unity中编辑动画
如图,dock是一个空gameObject,其下包含mouth_dn,mouth_up (应该叫lip_dn,lip_up更合适,这不是重点,先不改了),head,eye_left,eye_right ...
- POJ3187 Backward Digit Sums 【暴搜】
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4487 Accepted: 25 ...