链接:http://poj.org/problem?id=3348

Cows
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 6677   Accepted: 3020

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

Source

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

凸包求面积,先用Graham求出所有凸包的点,然后用叉乘积借助三角形求面积

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#define MAXX 10010 using namespace std; typedef struct point
{
int x;
int y;
}point; double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} double dist(point a,point b)
{
return sqrt((double)(a.x-b.x)*(a.x-b.x)+(double)(a.y-b.y)*(a.y-b.y));
} point c[MAXX];
int top;
point stk[MAXX]; bool cmp(point a,point b)
{
double len=crossProduct(c[],a,b);
if(len == )
{
return dist(c[],a)<dist(c[],b);
}
return len < ;
} void Graham(int n)
{
int tmp=;
for(int i=;i<n;i++)
{
if((c[i].x<c[tmp].x)||((c[i].x == c[tmp].x)&&(c[i].y<c[tmp].y)))
tmp=i;
}
swap(c[],c[tmp]);
sort(c+,c+n,cmp);
stk[]=c[];
stk[]=c[];
stk[]=c[];
top=;
for(int i=; i<n; i++)
{
while()
{
point a,b;
a=stk[top];
b=stk[top-];
if(crossProduct(a,b,c[i])<=)
{
top--;
}
else break;
}
stk[++top]=c[i];//printf("%d %d^^",stk[top].x,stk[top].y);
}
} double Area(int n)
{
if(n<)return ;
int i;
double ret=0.0;
for(i=; i<n; i++)
{
ret+=fabs(crossProduct(stk[],stk[i-],stk[i])/2.0);//printf("%lf---",ret);
}
return ret;
} int main()
{
int i,j,n,m;
scanf("%d",&n);
for(i=; i<n; i++)
{
scanf("%d%d",&c[i].x,&c[i].y);
}
Graham(n);//printf("%d**",top);
double ans=Area(top+);
printf("%d\n",(int)ans/);
return ;
}

poj 3348--Cows(凸包求面积)的更多相关文章

  1. POJ 3348 Cows 凸包 求面积

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

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

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

  3. POJ 3348 - Cows 凸包面积

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

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

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

  5. POJ 3348 Cows [凸包 面积]

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

  6. POJ 3348 Cows | 凸包模板题

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

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

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

  8. poj 3348 Cow 凸包面积

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

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

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

随机推荐

  1. sql创建删除修改表的基本操作

    1 建立表格 在建立好数据库以后,就可以根据储存资料的需求,使用SQL叙述建立所有需要的表格(table).建立表格的设定非常多,以建立"world.city"表格来说,它的叙述会 ...

  2. V4L2应用程序框架-二【转】

    本文转载自:http://blog.csdn.net/tommy_wxie/article/details/11371439 V4L2驱动框架 主设备号: 81 次设备号:    0-63    64 ...

  3. 如何杀掉D状态的进程?[zt]【转】

    转自:http://blog.csdn.net/chinalinuxzend/article/details/4288791 [-] 如何杀掉D状态的进程zt 相关博文   原贴:http://www ...

  4. Hibernate,JPA注解@ManyToMany

    @ManyToMany默认处理机制,当双向多对多关联中没有定义任何物理映射时, Hibernate根据以下规则生成相应的值: 关联表名: 主表表名+_下划线+从表表名: 关联到主表的外键名:从表用于关 ...

  5. HDU 5968:异或密码(暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=5968 题意:中文题意. 思路:一开始不会做,后来发现数据范围很小,而且那个数要是连续的,所以可能把所有情况枚举出 ...

  6. java 字符串处理

    第一张: 第二张:

  7. day3 python 集合 文件

    字典是无序的,列表是有序的 a='zhangsan' print (a[1]) a[2]=222 #字符串不能赋值 集合(set):把不同的元素组成一起形成集合 info=[1,2,34,5,6,7] ...

  8. ACM题目————zoj问题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:20322 解决:3560 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. ...

  9. 八大排序算法之二希尔排序(Shell Sort)

    希尔排序是1959 年由D.L.Shell 提出来的,相对直接排序有较大的改进.希尔排序又叫缩小增量排序 基本思想: 先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录 ...

  10. EF 用CallContext上下文管理

    public class ObjectContextFactory { private static CIK_NewsEntities context; public static DbContext ...