POJ 3348 最直接的凸包问题
题目大意:
给定一堆树的点,找到能组合成的最大面积,一个物体占50面积,求最多放多少物体
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-;
const int N = ;
double myabs(double x)
{
return x>?x:-x;
}
struct Point{
double x,y;
Point(double x= , double y=):x(x),y(y){}
};
Point p[N] , ch[N];
typedef Point Vector;
Vector operator+(Vector a , Vector b){
return Vector(a.x + b.x , a.y + b.y);
}
Vector operator-(Point a , Point b){
return Vector(a.x - b.x , a.y - b.y);
}
Vector operator*(Vector a, double b){
return Vector(a.x*b , a.y*b);
}
Vector operator/(Vector a, double b){
return Vector(a.x / b , a.y/b);
}
int dcmp(double x){
if(myabs(x) < eps) return ;
return x<?-:;
}
bool operator==(Point a ,Point b){
return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ;
}
bool operator<( Point a , Point b){
return dcmp(a.x-b.x)< || (dcmp(a.x-b.x)== && dcmp(a.y-b.y)<);
}
double Cross(Vector a , Vector b){
return a.x*b.y - b.x*a.y;
}
double get_polexy_area(Point *p , int n){
double ans = ;
for(int i=;i<n-;i++){
ans += Cross(p[i] - p[] , p[i+] - p[]);
}
return ans / ;
}
int ConvexHull(Point *p, int n) //凸包
{
sort(p, p+n);
n = unique(p, p+n) - p; //去重
int m = ;
for(int i = ; i < n; i++)
{
while(m > && Cross(ch[m-]-ch[m-], p[i]-ch[m-]) <= ) m--;
ch[m++] = p[i];
}
int k = m;
for(int i = n-; i >= ; i--)
{
while(m > k && Cross(ch[m-]-ch[m-], p[i]-ch[m-]) <= ) m--;
ch[m++] = p[i];
}
if(n > ) m--;
return m;
}
int main()
{
//freopen("test.in","rb",stdin);
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%lf%lf" , &p[i].x , &p[i].y);
}
int m = ConvexHull(p,n);
double area = get_polexy_area(ch , m);
int ans = (int)(area/);
printf("%d\n",ans);
}
return ;
}
POJ 3348 最直接的凸包问题的更多相关文章
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- 简单几何(凸包+多边形面积) POJ 3348 Cows
题目传送门 题意:求凸包 + (int)求面积 / 50 /************************************************ * Author :Running_Tim ...
- Cows - POJ 3348(凸包求面积)
题目大意:利用n棵树当木桩修建牛圈,知道每头牛需要50平的生存空间,求最多能放养多少头牛. 分析:赤裸裸的求凸包然后计算凸包的面积. 代码如下: --------------------------- ...
- poj 3348 Cows 求凸包面积
题目链接 大意: 求凸包的面积. #include <iostream> #include <vector> #include <cstdio> #include ...
- 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 | 凸包——童年的回忆(误)
想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...
- poj 3348:Cows(计算几何,求凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6199 Accepted: 2822 Description ...
随机推荐
- 解题报告:hdu 1073 Online Judge
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1073 Problem Description Ignatius is building an Onli ...
- orcl 11g 创建表空间
Oracle11g创建表空间语句 在plsql工具中执行以下语句,可建立Oracle表空间. /*分为四步 *//*第1步:创建临时表空间 */create temporary tablespa ...
- .Net应用自定义鼠标样式
(调用系统API的方法) 1.引用命名空间 using System.Runtime.InteropServices; 命名空间提供各种各样支持 COM 互操作 及平台调用服务的成员.using Sy ...
- [转]F# Samples 101 - Visual Studio 2010
http://code.msdn.microsoft.com/F-Samples-101-0576cb9f/sourcecode?fileId=18956&pathId=1045958806 ...
- ajax通过新闻id获取列表
<div class="index_main"> <div class="page_l"> <i ...
- Aspose.Word 的常见使用(2018-12-26 更新版)
Aspose.Word 的常见使用 起因 因项目需要,而且使用html转Word的时候,样式不兼容问题,于是只能使用Aspose.Word通过代码生成.下面是通过DocumentBuilder来设计W ...
- 学习笔记 第七章 使用CSS美化超链接
第7章 使用CSS美化超链接 学习重点 认识超链接 熟悉伪类 定义超链接样式 能够灵活设计符合页面风格的链接样式 7.1 定义超链接 在HTML5中建立超链接需要两个要素:设置为超链接的网页元素和 ...
- JAVA一些错误代码
//算术异常 ArithmeticExecption //空指针异常类 NullPointerException //类型强制转换异常 ClassCastException //数组负下标异常 Neg ...
- js中cookie的操作
JavaScript中的另一个机制:cookie,则可以达到真正全局变量的要求. cookie是浏览器 提供的一种机制,它将document 对象的cookie属性提供给JavaScript.可以由J ...
- Asp.Net 设计模式 之 “特殊”的单例模式
特殊的单例模式 要点在这里,提前预览: public SingleDemo() { name = "yy"; age = 20; //特殊的单例,this指代得失当前的Single ...