欢迎访问~原文出处——博客园-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 计算几何 凸包的更多相关文章

  1. POJ-3348 Cows 计算几何 求凸包 求多边形面积

    题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...

  2. poj3348 Cows 凸包+多边形面积 水题

    /* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...

  3. poj3348 Cows 凸包 叉积求多边形面积

    graham扫描法,参考yyb #include <algorithm> #include <iostream> #include <cstdio> #includ ...

  4. USACO Section 5.1 Fencing the Cows(凸包)

    裸的凸包..很好写,废话不说,直接贴代码. ----------------------------------------------------------------------------- ...

  5. 计算几何---凸包问题(Graham/Andrew Scan )

    概念 凸包(Convex Hull)是一个计算几何(图形学)中的概念.用不严谨的话来讲,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有点的.严谨的定义和相关概念参 ...

  6. 2018.07.03 POJ 3348 Cows(凸包)

    Cows Time Limit: 2000MS Memory Limit: 65536K Description Your friend to the south is interested in b ...

  7. POJ 3348 Cows(凸包+多边形面积)

    Description Your friend to the south is interested in building fences and turning plowshares into sw ...

  8. 计算几何-凸包-toleft test

    toLeftTest toLeftTest是判断一个点是否在有向直线左侧的算法. 当点s位于向量pq左侧时,toLeftTest返回true.当点s位于向量pq右侧时,toLeftTest返回fals ...

  9. 计算几何-凸包算法 Python实现与Matlab动画演示

    凸包算法是计算几何中的最经典问题之一了.给定一个点集,计算其凸包.凸包是什么就不罗嗦了 本文给出了<计算几何——算法与应用>中一书所列凸包算法的Python实现和Matlab实现,并给出了 ...

随机推荐

  1. springboot(八)自定义Filter、自定义Property

    自定义Filter 我们常常在项目中会使用filters用于录调用日志.排除有XSS威胁的字符.执行权限验证等等. Spring Boot自动添加了OrderedCharacterEncodingFi ...

  2. SysTick_CLKSourceConfig 这个函数

    systick的寄存器说明是在<Cortex M3权威指南>里说明了! 其实是有选择的,只是默认是AHB/8.通过设置systick的CTRL寄存器的bit2来设置时钟,设置如下: bit ...

  3. Linux之包管理工具总结[RPM/DPKG]-[YUM/APT]

    0.关键词解释 RPM:Red Hat Package Manager(原名),RPM Package Manager(现名,递归缩写,类似于GNU的命名); 解释:RPM软件包管理器 YUM:Yel ...

  4. luogu P2508 [HAOI2008]圆上的整点

    传送门 推荐去bzoj看个视频了解一下 不要妄想视频直接告诉你题解 但是视频告诉了你后面要用的东西 首先我们要求的是\(x^2+y^2=n^2(x,y\in Z)\)的\((x,y)\)对数,可以转化 ...

  5. 第16月第27天 pip install virtualenv ipython sip brew search

    1. pip install virtualenv virtualenv testvir cd testvir cd Scripts activate pip https://zhuanlan.zhi ...

  6. SpringBoot2.X自定义拦截器实战及新旧配置对比(核心知识)

    简介: 讲解拦截器使用,Spingboot2.x新版本配置拦截拦截器和旧版本SpringBoot配置拦截器区别讲解 1.@Configuration 继承WebMvcConfigurationAdap ...

  7. 改环境变量改出问题了,vi,ls这些命令都不能用了,怎么办

    1.出现这个问题肯定是以前的基本环境变量都用不了了(大部分情况就是多了一个空格) 解决办法: cd /usr/bin 下执行vi命令  修改环境变量  然后source /etc/profile   ...

  8. Python中的exec、eval使用实例

    Python中的exec.eval使用实例 这篇文章主要介绍了Python中的exec.eval使用实例,本文以简洁的方式总结了Python中的exec.eval作用,并给出实例,需要的朋友可以参考下 ...

  9. spring mvc常用配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  10. 004_i686和x86_64的区别

    找回TCL隐藏分区(转载) 用Wubi安装 Ubuntu 出现(Initranfs)问题的解决方案 i686和x86_64的区别 2009-04-11 08:19:31|  分类: 电脑问题 |  标 ...