POJ 3348 Cows (凸包模板+凸包面积)
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 求凸包的面积/50 我们求出凸包以后将凸包化成三角形用叉积求面积再加和
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
const double eps = 1e-;
const double dblinf = 9999999999.9;
const int maxn = 1e4+;
struct Point
{
double x,y;
}p[maxn];
int stk[maxn];
int top;
int dblcmp(double k)
{
if (fabs(k)<eps) return ;
return k>?:-;
}
double multi (Point p0,Point p1,Point p2)//叉乘
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double dis (Point a,Point b)
{
return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool anglecmp (Point a,Point b)//极角排序
{
int d = dblcmp(multi(p[],a,b));
if (!d) return dis(p[],a)<dis(p[],b);
return d>;
}
int n;
int main()
{
while (~scanf("%d",&n)){
double tx = dblinf,ty = dblinf;
int k;
for (int i=;i<n;++i){
scanf("%lf%lf",&p[i].x,&p[i].y);
int d = dblcmp(ty-p[i].y);
if (!d&&dblcmp(tx-p[i].x)>){
k=i;tx = p[i].x;
}
else if (d>){
k=i;
tx = p[i].x,ty = p[i].y;
}
}
p[k].x = p[].x,p[k].y = p[].y;
p[].x = tx,p[].y = ty;
sort(p+,p+n,anglecmp);
stk[] = ,
stk[] = ;
top = ;
for (int i=;i<n;++i){
while (top>=&&dblcmp(multi(p[stk[top-]] , p[i], p[stk[top]] ))>=) top--;
stk[++top] = i;
}
double area = ;
for (int i=;i<top;++i){
area+=fabs(multi(p[stk[]] , p[stk[i]] , p[stk[i+]] ));
}
area = area /2.0;//三角形面积和别忘/2.0
printf("%d\n",(int)(area/50.0));
}
return ;
}
POJ 3348 Cows (凸包模板+凸包面积)的更多相关文章
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- 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
题目传送门 题意:求凸包 + (int)求面积 / 50 /************************************************ * Author :Running_Tim ...
- ●POJ 3348 Cows
题链: http://poj.org/problem?id=3348 题解: 计算几何,凸包,多边形面积 好吧,就是个裸题,没什么可讲的. 代码: #include<cmath> #inc ...
- poj 3348:Cows(计算几何,求凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6199 Accepted: 2822 Description ...
- POJ 3348 Cows(凸包+多边形面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- POJ 3348 Cows | 凸包模板题
题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...
- poj 3348 Cows 求凸包面积
题目链接 大意: 求凸包的面积. #include <iostream> #include <vector> #include <cstdio> #include ...
随机推荐
- Java内置多线程框架Executor
JDK1.5之后,增加了一个Executor让我们能更好的使用多线程. 它位于java.util.concurrent包下 因为是JDK内置类库,我们不需要导入任何第三方jar包. 代码实例: imp ...
- MySql 5.7.20 绿色版安装
MySql 5.7.20 绿色版安装 一.MySql 安装 1.从官网下载绿色压缩包. 2.解压安装文件到指定目录 3.创建配置文件 my.ini 到解压文件的根目录,my.ini 配置文件如下,需将 ...
- day02-Javascript之document.write()方法
转行学开发,代码100天.——2018-03-18 document.write()方法作为Javascript的常用输出方式,可输出字符串,标签元素,变量等. document.write(&quo ...
- mysql错误:1093-You can’t specify target table for update in FROM clause的解决方法
update语句中包含的子查询的表和update的表为同一张表时,报错:1093-You can’t specify target table for update in FROM clause my ...
- vue-wacth监听事件
2019-08-05 0:20 Vue.js 监听属性 watch,我们可以通过 watch 来响应数据的变化. 以下实例通过使用 watch 实现计数器:(此时我就想了一下,好像绑定点击事件,也 ...
- Bootstrap 学习笔记9 标签页和工具提示插件
<ul class="nav nav-tabs"> <li class="active"><a href="#html5 ...
- MySQL replace into 与insert into
https://blog.csdn.net/helloxiaozhe/article/details/77427266 使用replace带来的问题 1.Replace into 操作在唯一键重复情况 ...
- 报错:Uncaught SyntaxError: Unexpected token)
用JSON格式传值时,js一直 报这个错误:Uncaught SyntaxError: Unexpected token) 错误位置是:result=eval('('+result+')'): 原因: ...
- Selenium+Java环境搭建
1. 安装JDK URL:http://www.oracle.com/technetwork/java/javase/downloads/ 2. 配置环境变量 JAVA_HOME = E:\Java\ ...
- 【报错】An error happened during template parsing (template: "class path resource [templates/adminManageCourse.html]")
页面显示: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing t ...