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 ...
随机推荐
- kafka 知识点整理
一个partition只能被同一个消费组内一个消费者消费,所以在同一时间点上,订阅到同一个partition的consumer必然属于不同的Consumer Group. 因此,如果设置的partit ...
- 134、TensorFlow检查点checkpoint文件中的信息
# 1.你想创建多少Saver对象就可以创建多少,如果你需要去保存和恢复不同的子图模型 # 同样的变量可以在不同的saver对象中被加载 # 只有在Saver.restore()方法被调用的时候才会对 ...
- Chrome开发小技巧--浏览器控制台现写并运行js代码--snippets
想简单等运行一段js代码,以前可能会新建一个html 里面包含script标签,或者引入一个js,然后chrome浏览器打开.这样很麻烦. 想再console控制台写,也不方便,换行处理麻烦. 基于在 ...
- Vmware 15 新建虚拟机黑屏
win10 的磁盘大小设置60的倍数 centos 使用 40g
- Win7 64位注册32位DLL
记忆力越来越差,备忘. 参考地址 https://support.microsoft.com/en-us/help/249873/how-to-use-the-regsvr32-tool-and-tr ...
- Lambda拉姆达表达式
拉姆达表达式常用于委托,也就是说拉姆达表达式是匿名函数,简单点就是函数. a => a.Equals("string"); //原形为: (a) => { return ...
- bash 特殊符号的含义
bash常见特殊符号及含义 linux中shell变量的含义解释
- Linux的mysql部署
1. 先输入代码yum install wget -y才可以做后面的 2.下载并安装MySQL官方的 Yum Repository 代码: wget -i -c http://dev.mysql ...
- java_第一年_JavaWeb(4)
HttpServletResponse对象 向客户端发送数据的方法: 通过getOutputStream()方法得到OutputStream对象,再通过write发送 通过getWriter()方法得 ...
- 解决java.net.BindException: Address already in use(Bind failed)端口占用问题
问题描述: 解决办法: sudo lsof -i:20101ps -ef|grep 9905kill -9 9905ps -ef|grep 9905 ------------------------- ...