poj 3348--Cows(凸包求面积)
链接:http://poj.org/problem?id=3348
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 6677 | Accepted: 3020 |
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
凸包求面积,先用Graham求出所有凸包的点,然后用叉乘积借助三角形求面积
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#define MAXX 10010 using namespace std; typedef struct point
{
int x;
int y;
}point; double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} double dist(point a,point b)
{
return sqrt((double)(a.x-b.x)*(a.x-b.x)+(double)(a.y-b.y)*(a.y-b.y));
} point c[MAXX];
int top;
point stk[MAXX]; bool cmp(point a,point b)
{
double len=crossProduct(c[],a,b);
if(len == )
{
return dist(c[],a)<dist(c[],b);
}
return len < ;
} void Graham(int n)
{
int tmp=;
for(int i=;i<n;i++)
{
if((c[i].x<c[tmp].x)||((c[i].x == c[tmp].x)&&(c[i].y<c[tmp].y)))
tmp=i;
}
swap(c[],c[tmp]);
sort(c+,c+n,cmp);
stk[]=c[];
stk[]=c[];
stk[]=c[];
top=;
for(int i=; i<n; i++)
{
while()
{
point a,b;
a=stk[top];
b=stk[top-];
if(crossProduct(a,b,c[i])<=)
{
top--;
}
else break;
}
stk[++top]=c[i];//printf("%d %d^^",stk[top].x,stk[top].y);
}
} double Area(int n)
{
if(n<)return ;
int i;
double ret=0.0;
for(i=; i<n; i++)
{
ret+=fabs(crossProduct(stk[],stk[i-],stk[i])/2.0);//printf("%lf---",ret);
}
return ret;
} int main()
{
int i,j,n,m;
scanf("%d",&n);
for(i=; i<n; i++)
{
scanf("%d%d",&c[i].x,&c[i].y);
}
Graham(n);//printf("%d**",top);
double ans=Area(top+);
printf("%d\n",(int)ans/);
return ;
}
poj 3348--Cows(凸包求面积)的更多相关文章
- 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 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- 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 ...
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...
随机推荐
- android 项目学习随笔三(Fragment )
1.在主页面(activity引用Fragment )的布局文件中定义FrameLayout ,加载Fragment <FrameLayout xmlns:android="http ...
- Backup: Numbers in Perl6
Perl6 is a new language, not a improved version of Perl5. Perl6 inherits many good features from man ...
- ubunu下用命令设置壁纸
ubunu下用命令设置壁纸: gsettings set org.gnome.desktop.background picture-uri “file:[fileName]” eg:gsettings ...
- grd文件结构
- 【Pro ASP.NET MVC 3 Framework】.学习笔记.9.SportsStore:Securing the Administration Features
1 设置表单身份认证 因为ASP.NET MVC基于ASP.NET平台的核心,所以我们可以使用ASP.NET Form的身份认证,这是保持用户登录轨迹通用的方法.现在介绍最基本的配置. 在Web.co ...
- plsql登录弹白框
环境:使用免安装版plsql,装有oracle服务端,plsql内有内置的oracle客户端,且tns配置正确. 问题:plsql登录弹白框 解决: 1.将oracle服务端的tns配置成与plsql ...
- webservice cxf error:java.lang.IllegalArgumentException: Argument(s) "type" can't be null.
客户端请求DTO和服务器端的DTO定义不一样,客户端必须定义@XmlAccessorType和@XmlType,如: @XmlAccessorType(XmlAccessType.FIELD) @Xm ...
- Could not write metadata for '/taiping-sol-insu-composite'.
Could not write metadata for '/taiping-sol-insu-composite'. 这是由于删除一个项目时,没有同时在硬盘上删除该项目,而后又到硬盘文件系统中删除了 ...
- run loop 输入源
做了一年多的IOS开发,对IOS和Objective-C深层次的了解还十分有限,大多还停留在会用API的级别,这是件挺可悲的事情.想学好一门语言还是需要深层次的了解它,这样才能在使用的时候得心应手,出 ...
- CI 配置验证规则
//判断表单域,提交表单显示对应的错误信息 $this->load->library('form_validation'); $config = array( ...