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 凸包+多边形面积的更多相关文章

  1. POJ 3348 Cows 凸包 求面积

    LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...

  2. poj3348 Cows 凸包+多边形面积 水题

    /* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...

  3. poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description ...

  4. POJ 3348 - Cows 凸包面积

    求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...

  5. POJ 3348 Cows (凸包模板+凸包面积)

    Description Your friend to the south is interested in building fences and turning plowshares into sw ...

  6. POJ 3348 Cows [凸包 面积]

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9022   Accepted: 3992 Description ...

  7. POJ 3348 Cows | 凸包模板题

    题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...

  8. POJ 3348 Cows | 凸包——童年的回忆(误)

    想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...

  9. poj 3348 Cow 凸包面积

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description ...

随机推荐

  1. 【Android多线程】异步任务AsyncTask类

    https://www.bilibili.com/video/av65170691?p=9 (本文为此视频观看笔记) 一.为什么需要此类 Handler繁琐 二.理解AsyncTask 2.1 参数( ...

  2. ip命令规范

    从centos7以前我们一直使用ifconfig命令来执行网络相关的任务,比如检查和配置网卡信息,但是ifconfig已经不再被维护,并且在最近版本的Linux中被废除了!ifconfig命令已经被i ...

  3. C/C++网络编程8——多进程服务器端之销毁僵尸进程

    上一节提到,当子进程执行结束,父进程还在执行,在父进程结束之前子进程会成为僵尸进程,那么怎么销毁僵尸进程呢?父进程主动接收子进程的返回值. 销毁僵尸进程的方法: 1:使用wait函数 2:使用wait ...

  4. Windows驱动开发-手动创建IRP

    手动创建IRP有以下几个步骤: 1,先得到设备的指针,一种方法是用IoGetDeviceObjectPointer内核函数得到设备对象指针,另外一种方法是用zwCreateFile内核函数先得到设备句 ...

  5. LeetCode中等题(二)

    题目一: 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复 ...

  6. java 实现用户自由选择字段实现导出EXCEL表格

    package com.thinkgem.jeesite.common.utils.excel; import java.io.File; import java.io.OutputStream; i ...

  7. Dynamic Programming(动态规划)

    钢材分段问题 #include<iostream> #include<vector> using namespace std; class Solution { public: ...

  8. 为Docker Desktop安装kubernet-dashboard

    在上一篇,在windows上,用最简方法(比其他的脚本法,提前拉取镜像简便太多了)安装好了docker desktop,并启用了内置的kubernetes. 这种安装方法实际上是在Hyper-v虚拟机 ...

  9. Python 基础之函数的嵌套与nonlocal修改局部变量及闭包函数

    一.函数的嵌套 嵌套在外层,称之为外函数 嵌套在里层,称之为内函数#例:def outer(): def inner():        print("I'm inner")    ...

  10. python 中的 赋值 浅拷贝 深拷贝

    1.对象的赋值 都是进行对象引用(内存地址)传递,即 b is a ,a 变 b也变 2.浅拷贝 会创建一个新的对象,对于对象中的元素,浅拷贝就只会使用原始元素的引用(内存地址) 当我们使用下面的操作 ...