POJ 3348:Cows 凸包+多边形面积
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 7739 | Accepted: 3507 |
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 <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; struct no
{
int x, y;
}node[10005]; int n;
int conbag[10005]; no orign;//原点 int dis(no n1, no n2)
{
return (n1.x - n2.x)*(n1.x - n2.x) + (n1.y - n2.y)*(n1.y - n2.y);
} int xmult(int x1, int y1, int x2, int y2)
{
return x1*y2 - x2*y1;
} int Across(no n1, no n2, no n3, no n4)
{
return xmult(n2.x - n1.x, n2.y - n1.y, n4.x - n3.x, n4.y - n3.y);
} int cmp(const void* n1, const void* n2)
{
int temp = Across(orign, *(no *)n1, orign, *(no *)n2); if (temp > 0)
{
return -1;
}
else if (temp == 0)
{
return (dis(orign, *(no *)n1) - dis(orign, *(no *)n2));
}
else
{
return 1;
}
} int main()
{ int i, j, k, min_x, pos_x;
double sum;
while (scanf("%d", &n) != EOF)
{
min_x = 1005;
for (i = 1; i <= n; i++)
{
cin >> node[i].x >> node[i].y;
if (node[i].x < min_x)
{
min_x = node[i].x;
pos_x = i;
}
else if (min_x == node[i].x&&node[i].y < node[pos_x].y)
{
pos_x = i;
}
}
orign = node[pos_x];
qsort(node + 1, n, sizeof(no), cmp); int pc = 1;
conbag[1] = 1;
conbag[++pc] = 2;
conbag[0] = 2; i = 3;
while (i <= n)
{
if (Across(node[conbag[pc - 1]], node[conbag[pc]], node[conbag[pc]], node[i]) >= 0)
{
conbag[++pc] = i++;
conbag[0]++;
}
else
{
pc--;
conbag[0]--;
}
} if (n < 3 || conbag[0]<3)
{
cout << 0 << endl;
}
else
{
sum = 0;
for (i = 1; i + 1 <= conbag[0]; ++i)
{
sum += abs((node[conbag[i]].x * node[conbag[(i + 1)]].y - node[conbag[i]].y * node[conbag[(i + 1)]].x));
}
sum += abs((node[conbag[i]].x * node[1].y - node[conbag[i]].y * node[1].x));
sum = sum / 2.0;
cout << (int)(sum / 50) << endl;
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 3348:Cows 凸包+多边形面积的更多相关文章
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- POJ 3348 Cows (凸包模板+凸包面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- POJ 3348 Cows [凸包 面积]
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9022 Accepted: 3992 Description ...
- POJ 3348 Cows | 凸包模板题
题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...
- POJ 3348 Cows | 凸包——童年的回忆(误)
想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
随机推荐
- String方法阅读笔记
String类常用方法 1.int Length(): 参数:无 返回值:调用此方法的字符串的长度(int) 实例: public class Test { public static void ma ...
- 【JAVA算法题】职业抢劫
题目 /*You are a professional robber planning to rob houses along a street. * Each house has a certain ...
- JavaScript的发展史
一.JavaScript发展历程 1. 诞生 JavaScript因互联网而生,紧跟浏览器的发展而发展. 1990年,欧洲核能研究所(CERN)科学家在互联网(Internet)基础上,发明了 ...
- Coursera 国内无法登陆问题
参考: 1.Coursera登不上去 | 知乎 2.Win10如何修改hosts | 百度经验 浏览器在访问https://www.coursera.org时,出现正在等待 d3njjcbhbojbo ...
- Ubuntu中安装pycharm
1.首先在官网上下载pycharm 2.下载完成后解压,进入到解压文件夹里的bin,找到pycharm.sh 3.使用终端启动:sh pycharm.sh 4.关于破解: 通过命令打开hosts:cd ...
- static关键字的作用是什么?
static的作用:常用来修饰变量. 全局变量被static修饰后,就称之为静态全局变量:局部变量被static修饰后,就称之为静态局部变量.统称为静态变量. 如果需要进一步解释下面的现象,可以了解i ...
- 使用win32com操作woord的方法记录
CSDN博客平台中有众多的 win32com 库操作word 的说明,对于通用的内容将一笔带过,主要介绍目前看来独一无二的内容. import win32com from win32com.clien ...
- 解决安装PyMySQL一直停在Building wheels for collected package:cryptography, cffi, pycparser的问题
我的运行环境为: 硬件:树莓派3b 系统:ubuntu_meta_16.04.2 因为项目需要,我在树莓派上搭建了基于python编程的Django的web框架,需要从MySQL中读取树莓派以及传感器 ...
- Struts2学习(六)
拦截器原理 1.如图所示,Struts2拦截器的实现原理相对简单,当请求struts2的action时,Struts 2会查找配置文件,并根据其配置实例化相对的拦截器对象,然后串成一个列表,最后一个一 ...
- IELTS Writing Task 1: two-chart answer
Thursday, January 09, 2020 The chart below shows the value of one country's exports in various categ ...