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 1235 统计同成绩学生人数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1235 Problem Description 读入N名学生的成绩,将获得某一给定分数的学生人数输出. ...
- ambari集群里如何正确删除历史修改记录(图文详解)
不多说,直接上干货! 答:这些你想删除的话得得去数据库里删除,最好别删除 . 现在默认就是使用好的配置 欢迎大家,加入我的微信公众号:大数据躺过的坑 人工智 ...
- ubu下编译安装php7
第一步: 安装依赖库zlib.libpng.freetype.jpegsrc.libxml2.libgd.freetds.mhash.libmcrypt.mcrypt(依赖于mhash和libmcry ...
- 移动端rem单位用法
1.rem(font size of the root element)是指相对于根元素的字体大小的单位,em(font size of the element)是指相对于父元素的字体大小的单位.它们 ...
- JDBC基础学习
1.概念:java数据库连接技术 2.JDBC:是一个规范,提供接口(面向接口编程) 3.JDBC API:提供程序员调用的接口和类,集成在java.sql 和javax.sql包中.如:Driver ...
- ava的动态代理机制详解
在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们不但要知道怎么通过AOP来满足的 ...
- logging模块基础3
1.logging模块的日志级别 CRITICAL = 50 #FATAL = CRITICAL ERROR = 40 WARNING = 30 #WARN = WARNING INFO = 20 D ...
- 计算机网络、OSI模型、TCP/IP族
一.计算机网络分类 1.按通信距离分类: 局域网:LAN,10m-1000m,房间.校园: 城域网:MAN,10km,城市: 广域网:WAN,100km以上,国家.全球. 二.OSI(Open Sys ...
- (转)淘淘商城系列——SSM框架整合之Service层整合
http://blog.csdn.net/yerenyuan_pku/article/details/72721108 上文我们一起学习了Dao层的整合,本文将教大家如何整合Service层. 我们需 ...
- C# 實現文件壓縮-- 背景:服務器Log.txt 過多,佔用過多硬盤空間,壓縮備份后節省空間資源
1.壓縮實現代碼如下: 調用ICSharpCode.SharpZipLib.dll(free software,可以搜到源碼). 轉移指定目錄文件夾轉移到目標文件夾 壓縮目標文件夾 刪除目標文件夾 u ...