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 ...
随机推荐
- 牛客提高D1t2 最小生成链
分析 我们发现可以把题目转化为:有一个序列a,问它的排列中相邻两个值异或的最大值的最小值 我们发现序列的构成一定是前几位全是一样的 从某一位开始左面全是0右面全是1 所以只要找到一种方案是的交界两个值 ...
- random——伪随机数生成模块
random——伪随机数生成模块 转自:https://blog.csdn.net/zhtysw/article/details/79978197 该模块包含构造伪随机数生成器的多个方法.对于整数,伪 ...
- Kubernetes 对象管理的三种方式
Kubernetes 中文文档 1. Kubernetes 对象管理的三种方式对比 Kubernetes 中的对象管理方式,根据对象配置信息的位置不同可以分为两大类: 命令式:对象的参数通过命令指定 ...
- Bootstrap,Bagging and Random Forest Algorithm
Bootstrap Method:在统计学中,Bootstrap从原始数据中抽取子集,然后分别求取各个子集的统计特征,最终将统计特征合并.例如求取某国人民的平均身高,不可能测量每一个人的身高,但却可以 ...
- python time 和日期相关模块
时间日期相关的模块 calendar 日历模块 time 时间模块 datetime 日期时间模块 timeit 时间检测模块 日历模块 calendar() 功能:获取指定年份的日历字符串 格式:c ...
- 洛谷P1265 公路修建——prim
给一手链接 https://www.luogu.com.cn/problem/P1265 这道题本质上就是最小生成树,题目描述就是prim的思想 TIP:注意稠密图和稀疏图的区别 #include&l ...
- 小B的询问(题解)(莫队)
小B的询问(题解)(莫队) Junlier良心莫队 题目 luoguP2709 小B的询问 code #include<bits/stdc++.h> #define lst long lo ...
- Codeforces - 1191C - Tokitsukaze and Discard Items - 模拟
https://codeforces.com/contest/1191/problem/C 一开始想象了一下,既然每次删除都是往前面靠,那么好像就是页数*页容量+空位数=最多容纳到的坐标. 至于为什么 ...
- python学习二十一天文件可读,可写,可执行的操作
文件无非是可读,可写,可执行的操作,分别对应的模式 r ,w,x,只读模式,只写模式,只执行模式,a模式为追加模式,实际也是写操作模式,r+,w+,a+ 可读写模式,下面详细说模式的用法 1,文件的模 ...
- xml&dom_sax&dom4j的常见操作
<? xml version =”1.0” encoding=”GB2312”?> <!-- 学生信息—><?xml-stylesheet type=”text/css” ...