poj 3348(凸包面积)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 8063 | Accepted: 3651 |
Description
Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.
However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.
Input
The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).
Output
You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.
Sample Input
4
0 0
0 101
75 0
75 101
Sample Output
151 题意:在一个树林里面养牛,每头牛需要50平方米的空间,问你总共可以养多少牛?
题解:凸包面积/50
#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
const int N = ;
const double eps = 1e-;
struct Point {
int x,y;
}p[N],Stack[N];
int n;
int cross(Point a,Point b,Point c){
return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
double getarea(Point a,Point b,Point c){
return cross(a,b,c)/2.0;
}
double dis(Point a,Point b){
return sqrt((double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));
}
int cmp(Point a,Point b){
if(cross(a,b,p[])>) return ;
if(cross(a,b,p[])==&&dis(b,p[])-dis(a,p[])>eps) return ;
return ;
}
int Graham(){
int k=;
for(int i=;i<n;i++){
if(p[i].y<p[k].y||(p[i].y==p[k].y)&&(p[i].x<p[k].x)) k=i;
}
swap(p[],p[k]);
sort(p+,p+n,cmp);
int top =;
Stack[] = p[];
Stack[] = p[];
Stack[] = p[];
for(int i=;i<n;i++){
while(top>=&&cross(p[i],Stack[top],Stack[top-])>=) top--;
Stack[++top] = p[i];
}
double area = ;
for(int i=;i<top;i++){
area+=getarea(Stack[i],Stack[i+],Stack[]); ///这里打成p..WA了几次..
}
return floor(area/);
}
int main()
{
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
if(n==||n==) {
printf("0\n");
continue;
}
int ans = Graham();
printf("%d\n",ans);
}
return ;
}
poj 3348(凸包面积)的更多相关文章
- Cows - POJ 3348(凸包求面积)
题目大意:利用n棵树当木桩修建牛圈,知道每头牛需要50平的生存空间,求最多能放养多少头牛. 分析:赤裸裸的求凸包然后计算凸包的面积. 代码如下: --------------------------- ...
- POJ 3348 /// 凸包+多边形面积
题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- poj 3348:Cows(计算几何,求凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6199 Accepted: 2822 Description ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- POJ 3348 Cows
题目大意: 给你n棵树,可以用这n棵树围一个圈,然后在圈里面可以养牛,每个牛需要50平方米的空间,问最多可以养多少牛? 其实就是求一个凸包,计算凸包面积,然后除以50,然后就得到答案,直接上模板了. ...
- poj 1265 Area 面积+多边形内点数
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5861 Accepted: 2612 Description ...
随机推荐
- android的dmtracedump工具生成trace文件图片 'dot' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
http://jingyan.baidu.com/article/c910274bfa6c1fcd361d2df7.html http://www.cnblogs.com/albert1017/p/3 ...
- MySQL之查询性能优化(四)
优化特定类型的查询 COUNT()的作用 COUNT()是一个特殊函数,有两个非常不同的作用:它可以统计某个列值的数量,也可以统计行数.在统计列值时要求列值是非空的(不统计NULL). 如果在COUN ...
- (C)spring boot读取自定义配置文件时乱码解决办法
这是入门的第三天了,从简单的hello spring开始,已经慢慢接近web的样子.接下来当然是读取简单的对象属性了. 于是按照网上各位大神教的,简单写了个对象book,如上一篇(B),其他配置不需要 ...
- laravel5.5容器
目录 1. 比较典型的例子就是 cache 缓存 2. 容器顾名思义,其实就是完成存取过程 2.1 绑定过程 简单绑定 绑定单例 绑定实例 绑定初始数据 2.2 解析过程 容器主要是为了实现控制反转, ...
- USACO Section1.1 Friday the Thirteenth 解题报告
friday解题报告 —— icedream61 博客园(转载请注明出处) -------------------------------------------------------------- ...
- mac虚拟机上(centos系统)怎样实现共享本机文件
首先加载vboxadditions,可以从https://download.virtualbox.org/virtualbox/下载,记得一定要跟virtualBox版本对应 然后打开virtualb ...
- 数据库——pymysql模块的使用(13)
1.基本用法——建立链接,获取游标,执行sql语句,关闭 建立远程链接账号和权限 mysql> grant all on *.* to '; Query OK, rows affected, w ...
- drf解决跨域问题 使用 django-corse-headers扩展
跨域CORS 使用django-corse-headers扩展 安装 pip install django-cors-headers 添加应用 INSTALLED_APPS = ( ... 'cors ...
- ASP.NET Core [2]:Middleware-请求管道的构成(笔记)
原文链接:http://www.cnblogs.com/RainingNight/p/middleware-in-asp-net-core.html 中间件处理请求主要分为三个阶段:1. 中间件的注册 ...
- Python的HttpClient实现
Python版本3.4(注意python的版本,python2和python3的写法不一样) 其实无非就是客户端的请求,所以python中这里使用的是urllib.request模块.主要注意的是he ...