Cows - POJ 3348(凸包求面积)
题目大意:利用n棵树当木桩修建牛圈,知道每头牛需要50平的生存空间,求最多能放养多少头牛。
分析:赤裸裸的求凸包然后计算凸包的面积。
代码如下:
-------------------------------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std; const int MAXN = 1e4+;
const double EPS = 1e-; int sta[MAXN], top; struct point
{
double x, y; point(double x=, double y=):x(x), y(y){}
point operator - (const point &t)const{
return point(x-t.x, y-t.y);
}
double operator *(const point &t)const{
return x*t.x + y*t.y;
}
double operator ^(const point &t)const{
return x*t.y - y*t.x;
}
}p[MAXN];
int Sign(double t)
{
if(t > EPS)return ;
if(fabs(t) < EPS)return ;
return -;
}
double Dist(point a, point b)
{
return sqrt((a-b)*(a-b));
}
bool cmp(point a, point b)
{
int t = Sign((a-p[])^(b-p[])); if(t == )
return Dist(a, p[]) < Dist(b, p[]);
return t > ;
}
void Graham(int N)
{
int k=; for(int i=; i<N; i++)
{
if(p[k].y>p[i].y || (Sign(p[k].y-p[i].y)== && p[k].x > p[i].x))
k = i;
}
swap(p[], p[k]);
sort(p+, p+N, cmp); sta[]=, sta[]=, top=; if(N < )
{
top = N-;
return ;
} for(int i=; i<N; i++)
{
while(top> && Sign((p[i]-p[sta[top]])^(p[sta[top-]]-p[sta[top]])) <= )
top--;
sta[++top] = i;
}
}
int main()
{
int N; while(scanf("%d", &N) != EOF && N)
{
for(int i=; i<N; i++)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
} Graham(N); double area=; for(int i=; i<top; i++)
{
double a = Dist( p[ sta[] ], p[ sta[i] ] );
double b = Dist( p[ sta[] ], p[ sta[i+] ] );
double c = Dist( p[ sta[i] ], p[ sta[i+] ] );
double q = (a+b+c) / ; area += sqrt(q*(q-a)*(q-b)*(q-c));
} printf("%d\n", (int)(area/50.0));
} return ;
}
Cows - POJ 3348(凸包求面积)的更多相关文章
- poj 3348--Cows(凸包求面积)
链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: ...
- POJ 3348 /// 凸包+多边形面积
题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj 3348(凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8063 Accepted: 3651 Description ...
- uva 10065 (凸包+求面积)
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...
- An Easy Problem?! - POJ 2826(求面积)
题目大意:有两块木板交叉起来接雨水,问最多能接多少. 分析:题目描述很简单,不过有些细节还是需要注意到,如下图几种情况: #include<stdio.h> #include< ...
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- poj 3348 Cows 求凸包面积
题目链接 大意: 求凸包的面积. #include <iostream> #include <vector> #include <cstdio> #include ...
随机推荐
- 使用Ubuntu 新建vpn过程
1.更新软件源 sudo apt-get update 2.安装pip sudo apt-get install python-pip 3.安装shadowsocks s ...
- leetcode中一些要用到动态规划的题目
需要仔细回顾的题目: 1.Interleaving String 交叉存取字符串 2.Decode Ways 字符串解码 3.Subsets Subsets II 求一个 ...
- php 常用几个函数
function foo($arg){ $arg_num = func_num_args(); // 获取函数参数的个数 $args = func_get_args(); // 获取 ...
- js学习--DOM操作详解大全一(浏览器对象)
一.客户端中的window对象 window对象表示当前浏览器的窗口,它是一个顶级对象,我们创建的所有对象.函数.变量都是window对象的成员. window对象自带了一些非常有用的方法.属性. w ...
- js获取时间天数
date2必须大于date1 function getDays(date1,date2){ /*获取之间的天数*/ /*date1,date2都是date格式*/ var getd=(date2.ge ...
- android code 和js的交互
小弟现在需要android code 和js的交互.出现了问题,求大家带一带啊. 我的页面:<!DOCTYPE html><html lang="en">& ...
- c++构造函数谁先执行的问题
看到网上一哥们的帖子 http://blog.csdn.net/maray/article/details/7761709 东西不多就转发了 1 #include <iostream> u ...
- IntelIoT技术笔记Maven
1.Maven project facet配置 错误信息: One or more constraints have not been satisfied.以及Cannot change versio ...
- 常用machine learning数据集
ImageNet:非商业化的可视化大数据 截止到2015年5月1日,ImageNet数据库拥有超过1500万的图像. cifar10:10类物体识别数据集 数据集中包含60,000幅32*32图像,共 ...
- sqlserver 学习
http://www.cnblogs.com/CareySon/category/411344.html SQL Server查找的最小单位实际上是页.也就是说即使你只查找一行很小的数据,SQL Se ...