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. SpringBoot启动使用elasticsearch启动异常:Received message from unsupported version:[2.0.0] minimal compatible

    SpringBoot启动使用elasticsearch启动异常:Received message from unsupported version:[2.0.0] minimal compatible ...

  2. 简单实用的matlab柱状图显示比例及计数

    这个小代码用于matlab柱状图显示比例及数值, 函数如下: function myhist(x) % myhist Codeby SimonLiang % Email:idignew@126.com ...

  3. getopts以参数形式执行diag

    #!/bin/bash ################################################################################# # Copy ...

  4. nginx访问目录是没加/的重定向控制

    static 模块提供了root与alias功能:发现目标是目录时:但URI末尾未加/时:会返回301重定向:重定向后会加/ 指令 Syntax: server_name_in_redirect on ...

  5. 一键设置Fluent环境变量小程序

    使用视频教程优酷播放地址: https://v.youku.com/v_show/id_XNDU2MTkwNDg5Mg==.html?spm=a2hzp.8244740.0.0 一键设置环境变量小软件 ...

  6. Idea牛逼插件,拿走不谢

    1.grep console java 开发的过程中,日志都会输出到console,输出的内容是非常多的,所以需要有一个工具可以方便的查找日志,或者可以非常明显显示我们关注的内容,grep conso ...

  7. hbase meta中分区信息错误的记录

    bulk write hbase 时遇到下面的错误: 19/03/20 02:16:02 ERROR LoadIncrementalHFiles: IOException during splitti ...

  8. express框架开发接口部署线上环境PM2

    1.PM2介绍 PM2是一个线上环境下,用于启动nodejs进程守护的工具,用来保证服务的稳定及分摊服务器进程和压力. 2.下载安装 npm install pm2 -g  => pm2 --v ...

  9. 去除input边框 input去除边框 去除input获取焦点时的蓝色外边框

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. Kali aircrack-ng wifi密码破解(暴力)

    1.kali linux安全渗透 2.工具aircrack-ng 3.ifconfig查看你的网卡信息,wlan0即无线网卡,注意,如果没有发现网卡可能是芯片不能被识别,建议选择网卡芯片为3037或r ...