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> # ...
随机推荐
- (栈的应用5.2.2)POJ 2106 Boolean Expressions(表达式求值)
/* * POJ_2106.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...
- android 学习随笔二十(多媒体编程 )
1.图片处理 加载大图片 图片大小的计算 图片大小 = 图片的总像素 * 每个像素占用的大小 * 单色图:每个像素占用1/8个字节* 16色图:每个像素占用1/2个字节* 256色图:每个像素占用1个 ...
- 给文件加ip访问限制
获取IP: function getIP(){ return isset($_SERVER['HTTP_X_FORWARDED_FOR'])? $_SERVER['HTTP_X_FORWARDED_F ...
- plsql登录弹白框
环境:使用免安装版plsql,装有oracle服务端,plsql内有内置的oracle客户端,且tns配置正确. 问题:plsql登录弹白框 解决: 1.将oracle服务端的tns配置成与plsql ...
- HDU 2236:无题II(二分搜索+二分匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=2236 题意:中文题意. 思路:先找出最大和最小值,然后二分差值,对于每一个差值从下界开始枚举判断能不能二分匹配. ...
- Maven invalid task...
执行maven构建项目报错: Invalid task '‐DgroupId=*': you must specify a valid lifecycle phase, or a goal in th ...
- myeclipse的快捷键和myeclipse快捷键设置
1.Ctrl+M切换窗口的大小 2.Ctrl+Q跳到最后一次的编辑处 3.F2当鼠标放在一个标记处出现Tooltip时候按F2则把鼠标移开时Tooltip还会显示即Show Tooltip D ...
- C#事物执行数据
public class sqlservershiwu { public string sqlconString = "Data Source=.;Initial Catalog=TestD ...
- HDU(2255),KM算法,最大权匹配
题目链接 奔小康赚大钱 Time Limit: 1000/1000MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- php获取当前时间和转换格式
## 获取时间和转换格式```//1.time():返回当前时间的Unix时间戳$stimestamp = time();$date = date("Y-m-d h:i:sa",$ ...