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实现,并给出了 ...
随机推荐
- winform,WPF 释放内存垃圾,减少资源占用方法
[System.Runtime.InteropServices.DllImport("kernel32.dll")] public static extern boo ...
- 淘淘商城之SSM框架整合概要
一.后台系统所用的技术 1)框架:Spring + SpringMVC + Mybatis: 2)前端:EasyUI: 3)数据库:mysql 二.创建数据库 1)安装mysql数据库: 2)在mys ...
- C# 面向对象的base的使用
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- Wannafly挑战赛21 E 未来城市规划
传送门 题目中给的信息很难直接维护,但是可以考虑一条边对答案的贡献 在以\(x\)为根的子树里,如果一条边\(i\)的权值为\(w_i\),这条边深度更深的端点为\(to_i\),那么这条边对这个子树 ...
- python yield from
def kk(): print (1) yield print (2) return 3 k=kk() def hello(k): print("Hello world!") r ...
- B - Internship (网络流关键割边)
题目链接:https://cn.vjudge.net/contest/281961#problem/B 题目大意:给你n个城市,中间有一些中转站,然后给你终点,再给你l条轨道以及流量,问你增加哪几条轨 ...
- 【漏洞挖掘】攻击对外开放的Docker API接口
https://medium.com/@riccardo.ancarani94/attacking-docker-exposed-api-3e01ffc3c124 1)场景 攻击开放在互联网的Dock ...
- 七、Sparse Autoencoder介绍
目前为止,我们已经讨论了神经网络在有监督学习中的应用.在有监督学习中,训练样本是有类别标签的.现在假设我们只有一个没有带类别标签的训练样本集合 ,其中 .自编码神经网络是一种无监督学习算法,它使用 ...
- High level GPU programming in C++
https://github.com/prem30488/C2CUDATranslator http://www.training.prace-ri.eu/uploads/tx_pracetmo/GP ...
- 使用光盘搭建本地yum源
刚装好的系统,想安装一些常用软件和一些包组的时候,就可以使用安装光盘搭建本地yum 第一步:挂载安装光盘 mount /dev/cdrom /mnt 第二步:编辑repo yum源文件 [root@l ...