POJ3348 Cows 计算几何 凸包
欢迎访问~原文出处——博客园-zhouzhendong
去博客园看该题解
题目传送门 - POJ3348
题意概括
求凸包面积(答案÷50)
题解
凸包裸题。
代码
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
const int N=10005;
const double Eps=1e-8;
int n,st[N],top;
int Dcmp(double x){
if (fabs(x)<Eps)
return 0;
return x<0?-1:1;
}
struct Point{
double x,y;
}p[N],O;
double sqr(double x){
return x*x;
}
double dis(Point a,Point b){
return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
bool cmp_O(Point a,Point b){
if (Dcmp(a.y-b.y)==0)
return a.x<b.x;
return a.y<b.y;
}
double cross(Point a,Point b,Point c){
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
bool cmp_Angle(Point a,Point b){
double c=cross(O,a,b);
if (Dcmp(c)==0)
return dis(O,a)<dis(O,b);
return Dcmp(c)>0;
}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
for (int i=2;i<=n;i++)
if (!cmp_O(p[1],p[i]))
swap(p[1],p[i]);
O=p[1];
sort(p+2,p+n+1,cmp_Angle);
memset(st,0,sizeof st);
top=0;
st[++top]=1,st[++top]=2;
for (int i=3;i<=n;i++){
while (top>=2&&Dcmp(cross(p[st[top-1]],p[st[top]],p[i]))<=0)
top--;
st[++top]=i;
}
double ans=0;
for (int i=2;i<top;i++)
ans+=fabs(cross(p[st[1]],p[st[i]],p[st[i+1]]));
ans/=2;
printf("%d",(int)(ans/50));
return 0;
}
POJ3348 Cows 计算几何 凸包的更多相关文章
- POJ-3348 Cows 计算几何 求凸包 求多边形面积
题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...
- poj3348 Cows 凸包 叉积求多边形面积
graham扫描法,参考yyb #include <algorithm> #include <iostream> #include <cstdio> #includ ...
- USACO Section 5.1 Fencing the Cows(凸包)
裸的凸包..很好写,废话不说,直接贴代码. ----------------------------------------------------------------------------- ...
- 计算几何---凸包问题(Graham/Andrew Scan )
概念 凸包(Convex Hull)是一个计算几何(图形学)中的概念.用不严谨的话来讲,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有点的.严谨的定义和相关概念参 ...
- 2018.07.03 POJ 3348 Cows(凸包)
Cows Time Limit: 2000MS Memory Limit: 65536K Description Your friend to the south is interested in b ...
- POJ 3348 Cows(凸包+多边形面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- 计算几何-凸包-toleft test
toLeftTest toLeftTest是判断一个点是否在有向直线左侧的算法. 当点s位于向量pq左侧时,toLeftTest返回true.当点s位于向量pq右侧时,toLeftTest返回fals ...
- 计算几何-凸包算法 Python实现与Matlab动画演示
凸包算法是计算几何中的最经典问题之一了.给定一个点集,计算其凸包.凸包是什么就不罗嗦了 本文给出了<计算几何——算法与应用>中一书所列凸包算法的Python实现和Matlab实现,并给出了 ...
随机推荐
- Keil5下载STM32库
1.http://www.keil.com/dd2 2.3.以STM32L051C8为例 下载即可.
- JavaScript之函数调用与被调用的上下文对象this
不同的调用机制决定了函数上下文对象的不同: 1. 作为普通函数进行调用时,其上下文是全局对象window; 2. 作为(对象)方法进行调用时,其上下文对象时拥有该方法的对象; 3. 作为构造器( ...
- The folder can’t be opened because you don’t have permission to see its contents.
1 自己在windows上面copy过去的文件夹,在Mac下面无法查看 一开始以为是windows文件的权限问题,然后 自己赋予了everyone所有的权限,结果在Mac上面还是无法打开文件夹 2 最 ...
- mysql案例~关于mysql的配置文件个人见解
mysql 设置参数解读一 mysql的参数分为几类 1 session级别可以设置 2 global级别可以设置 3 session+global级别可以设置 4 ...
- 2018-2019-2 网络对抗技术 20165227 Exp2 后门原理与实践
2018-2019-2 网络对抗技术 20165227 Exp2 后门原理与实践 (1)例举你能想到的一个后门进入到你系统中的可能方式? 接收邮件的方式 (2)例举你知道的后门如何启动起来(win及l ...
- SILC超像素分割算法详解(附Python代码)
SILC算法详解 一.原理介绍 SLIC算法是simple linear iterative cluster的简称,该算法用来生成超像素(superpixel) 算法步骤: 已知一副图像大小M*N,可 ...
- 重新学习Servlet
package javax.servlet; import java.io.IOException; public interface Servlet { public void init(Servl ...
- windows系统中hosts文件位置
C:\Windows\System32\drivers\etc\hosts 10.0.0.213 mr1.bic.zte.com 10.0.0.2 mr2.bic.zte.com 10.0.0.102 ...
- exp自动备份在bat中不执行
在命令行前加cd c:\users\...... 先定位进入可以exp的目录下,再执行exp
- spring和hibernate集成事物管理配置方法
spring+hibernate,采用声明式事务 1.声明式事务配置 * 配置SessionFactory * 配置事务管理器 * 事务的传播特性 * 那些类那些方法使用事务 2.编写业务逻辑方法 * ...