POJ3348Cows 凸包+多边形求面积

个人分类: 计算几何凸包

Language: Default

Cows

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 7633   Accepted: 3467

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 yseparated 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平方养一头牛,问最多能养多少牛

求凸包 + (int)求面积 / 50

//POJ--1228
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define  eps 1e-8
using namespace std;struct  point
{double x,y;
};
point p[1010],stack[1010];
int N,top;
//叉积
double multi(point p1, point p2, point p3)
{return (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
}
//距离公式
double dis(point a, point b)
{return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
//极角排序比较器
bool cmp(point c, point d)
{double k = multi(p[0], c, d);if(k>0) return true;if(k<0) return false;return dis(c,p[0])<dis(d,p[0]);
}
//求凸包
void Convex()
{//第一个点p[0]为左下角的点for(int i = 1; i < N; i++){point temp;if(p[i].y < p[0].y || ( p[i].y == p[0].y && p[i].x < p[0].x)){temp = p[i];p[i] = p[0];p[0] = temp;}}sort(p + 1, p+N , cmp);//不包括第一个点stack[0] = p[0];stack[1] = p[1];top = 1;for(int i = 2; i < N; i++){while(top >= 1 && multi(stack[top - 1], stack[top], p[i]) < 0)     top--;//共线的点也压入凸包内;top++;stack[top] = p[i];}
}
//判断每条边是否有至少三个点;
bool judge()
{for(int  i=1;i<top;i++){if((multi(stack[i-1],stack[i+1],stack[i]))!=0&&(multi(stack[i],stack[i+2],stack[i+1]))!=0)return false;}return true;
}
double area()
{double res=0;for(int i=1;i<top;i++){res+=(multi(stack[0],stack[i],stack[i+1])/2.0);}return res;
}
int main()
{while(scanf("%d",&N)!=EOF){for(int i=0;i<N;i++)scanf("%lf%lf",&p[i].x,&p[i].y);Convex();int num=(int)floor(area()/50.0);printf("%d\n",num);}return 0;
}

POJ3348 Cows【凸包+多边形求面积】相关推荐

  1. HDOJ2036改革春风吹满地笔记——任意多边形求面积

    题目地址 学习了任意多边形的计算,通过向量叉乘来进行计算. 计算公式 如果逆时针给出坐标,求得是正的,就是答案.如果顺时针给出坐标,求得是负,需要变正 具体推导过程 博客地址1 还学了海伦公式求三角形 ...

  2. zoj 1010 (线段相交判断+多边形求面积)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds      Mem ...

  3. JTS求多边形重合面积

    前言 通过JTS可以实现多边形求面积以及多个多边形求重合度,本文章只列举几个简单的使用例子. 详细的文档使用链接:http://www.tsusiatsoftware.net/jts/main.htm ...

  4. 洛谷——P1183 多边形的面积

    P1183 多边形的面积 多边形求面积公式: $\frac {\sum_{i=0}^{n-1}(x_iy_{i+1}-y_ix_{i+1})}{2}$ #include<bits/stdc++. ...

  5. opencv findContours()轮廓特征分析大全(求面积、周长、几何矩、质心、凸包、最小外接矩形、最小外接三角形、最小外接椭圆等)

    文章目录 前言 一.效果 二.opencv对应函数介绍 1.轮廓面积 2.轮廓周长 3.轮廓几何矩 4.轮廓的最大外接矩形 5.轮廓的凸包 6.轮廓的最小外接矩形 7.轮廓的最小外接三角形 8.轮廓的 ...

  6. 转:求多边形的面积 算法几何

    我还是简单解释一下,如果是没有读过高等数学的朋友,也让你大致明白. 定积分的本质是求和,计算f(x)在积分区间[a,b]上的一个和S,首先把积分区间分成n份,这样的分法记为λ,记Δ(λ)=max{Δx ...

  7. c语言给坐标求多边形面积,多边形的面积问题

    多边形的面积问题 设构成多边形的坐标串为(xi,yi)(i=1,2,--,n),求此多边形面积A. #include #define N 10 float Area(float (*x)[2],int ...

  8. golang求多边形相交面积

    直接上代码, 根据网上c++版本翻译 package mainimport ("fmt""math" )const maXn int = 300 const e ...

  9. 已知空间中的三点 求三角形面积_梳理中关联 变式中提升——“多边形的面积”整理与复习教学实践...

    向你介绍我是谁 大家好!我是一课研究第22组成员王冬,来自浙江省瑞安市莘塍第六小学.很高兴与您在此相遇! 本期内容有哪些 ○听一听:周卫东<数学教学,需要沉潜> ○读一读:梳理中关联,变式 ...

最新文章

  1. iwebshop商户手机模板_认证小红书企业号手机端最详细的认证流程!认证之前看这篇!...
  2. 2019年计算机视觉将继续承担哪些作用?
  3. android开发 获取相册名称_Android开发之获取相册照片和获取拍照照片
  4. cannon的英文名_Cannon[坎农]的中文翻译及英文名意思
  5. 三菱plc编程实例3000_三菱入门PLC编程PLC系统程序包括哪些
  6. 智慧城市、智慧园区、智慧交通、行业经营看板、运行管理大屏、图表模板、公司经营看板、大屏可视化、BI可视化模板、智慧工厂、办公、能源、餐饮、校园、人力资源、行政、汽车、房地产、保险、医院、axure原型
  7. u盘安装linux系统自动关机,将u盘拔出后电脑自动关机怎么解决【解决方法】
  8. python词云可视化视频_Python数据分析-可视化-wordcloud词云
  9. Luogu1169 [ZJOI2007]棋盘制作
  10. AlphaBlend失败,错误码87
  11. java程序设计大赛acm_转载(ACM国际大学生程序设计大赛)
  12. 移动app原型设计工具:Flinto for Mac
  13. 记录一次生产环境偶发HTTP响应406报错问题
  14. 蚂蚁森林 离线爬虫自动收能量,养小鸡,等各种操作
  15. python文字游戏攻防_一个简单的孙悟空斗牛魔王的文字游戏
  16. C#输入身高体重求BMI
  17. 不是公网ip怎么搭建服务器
  18. 酞菁铜磺酸(CuPcS),酞青铜相对分子质量|齐岳生物
  19. XXE漏洞的详解与利用
  20. C# winform 学习(一)

热门文章

  1. javaScriptDay01
  2. Check for Palindromes(算法)
  3. STM32的USART中断死循环,形成死机。
  4. 《大话操作系统——做坚实的project实践派》(6)
  5. 判定一个点是否在三角形内
  6. iOS真机调试 for Xcode 5
  7. greenplum分区表查看所占空间大小
  8. recovery v1跟recovery v2的区别
  9. 控制好你的 Wordpress 侧边栏
  10. java负数右移_Java中负数的右移