来源 poj 3348

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

凸包求面积,水,分成三角形算出来

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
struct Point{
int x,y,temp;
}p[10005],s[10005];
int top;
int direction(Point p1,Point p2,Point p3) { return (p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y); }//´Ó1µ½2µÄÏòÁ¿ºÍ´Ó1µ½3µÄÏòÁ¿£¬Èç¹ûµ½3µÄÏòÁ¿ÔÚµ½2µÄÓұߣ¬¾ÍÊÇ´óÓÚ0µÄ
double dis(Point p1,Point p2) { return sqrt(1.0*(p2.x-p1.x)*(p2.x-p1.x)+1.0*(p2.y-p1.y)*(p2.y-p1.y)); }
bool cmp(Point p1,Point p2)//¼«½ÇÅÅÐò
{
int temp=direction(p[0],p1,p2);
if(temp<0)return true ;
if(temp==0&&dis(p[0],p1)<dis(p[0],p2))return true;
return false;
}
void Graham(int n)
{
int pos,minx,miny;
minx=miny=inf;
for(int i=0;i<n;i++)//ÕÒ×îÏÂÃæµÄ»ùµã
if(p[i].y<miny||(p[i].y==miny&&p[i].x<minx))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
swap(p[0],p[pos]);
sort(p+1,p+n,cmp);
p[n]=p[0];
s[0]=p[0];s[1]=p[1];s[2]=p[2];
top=2;
for(int i=3;i<=n;i++)
{
while(direction(s[top-1],s[top],p[i])>=0&&top>=2)top--;//ËùÒÔÔÚÓұߵĻ°£¬¾ÍÒªÍË»ØÈ¥¸²¸Ç
s[++top]=p[i] ;
}
}
double area(Point a,Point b,Point c)
{
double x1,x2,x3,x;
x1=dis(a,b);
x2=dis(a,c);
x3=dis(b,c);
x=(x1+x2+x3)/2;
return sqrt(x*(x-x1)*(x-x2)*(x-x3));
}
int main()
{
int n;
cin>>n;
rep(i,0,n)
sf("%d%d",&p[i].x,&p[i].y);
Graham(n);
double sum=0;
rep(i,1,top-1)
{
sum+=area(s[0],s[i],s[i+1]);
}
pf("%d",(int)sum/50);
return 0;
}

I - Cows的更多相关文章

  1. [LeetCode] Bulls and Cows 公母牛游戏

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  2. POJ 2186 Popular Cows(Targin缩点)

    传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 1292 ...

  3. POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)

    传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Acce ...

  4. LeetCode 299 Bulls and Cows

    Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...

  5. [Leetcode] Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  6. 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列

    第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...

  7. POJ2186 Popular Cows [强连通分量|缩点]

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31241   Accepted: 12691 De ...

  8. Poj2186Popular Cows

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31533   Accepted: 12817 De ...

  9. [poj2182] Lost Cows (线段树)

    线段树 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacula ...

  10. 【POJ3621】Sightseeing Cows

    Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8331   Accepted: 2791 ...

随机推荐

  1. 几种php加速器比较

    一.PHP加速器介绍 PHP加速器是一个为了提高PHP执行效率,从而缓存起PHP的操作码,这样PHP后面执行就不用解析转换了,可以直接调用PHP操作码,这样速度上就提高了不少. Apache中使用mo ...

  2. Python中文转拼音代码(支持全拼和首字母缩写)

    本文的代码,从https://github.com/cleverdeng/pinyin.py升级得来,针对原文的代码,做了以下升级:     1 2 3 4 1.可以传入参数firstcode:如果为 ...

  3. 对actuator的管理端点进行ip白名单限制(springBoot添加filter)

    在我们的SpringCloud应用中,我们会引入actuator来进行管理和监控我们的应用 常见的有:http://www.cnblogs.com/yangzhilong/p/8378152.html ...

  4. Kriging插值法

    克里金法是通过一组具有 z 值的分散点生成估计表面的高级地统计过程.与插值工具集中的其他插值方法不同,选择用于生成输出表面的最佳估算方法之前,有效使用克里金法工具涉及 z 值表示的现象的空间行为的交互 ...

  5. Boost中的智能指针(转)

    这篇文章主要介绍 boost中的智能指针的使用.(转自:http://www.cnblogs.com/sld666666/archive/2010/12/16/1908265.html) 内存管理是一 ...

  6. MAC EI Capitan上更新系统自带SVN版本号(关闭SIP方能sudo rm)

    继昨晚之后.决定更新系统自带的svn.自带的svn版本号是1.7.看官网svn:http://www.wandisco.com/subversion/download#osx 最新版本号是1.9.13 ...

  7. Android studio ButterKnife插件

    1.功能:给所有的有id的控件添加注解 2.github地址 https://github.com/avast/android-butterknife-zelezny 3.插件下载地址 http:// ...

  8. What-does-git-remote-and-origin-mean

    https://www.quora.com/What-does-git-remote-and-origin-mean https://stackoverflow.com/questions/29235 ...

  9. [Big Data - Kafka] Kafka设计解析(三):Kafka High Availability (下)

    Kafka是由LinkedIn开发的一个分布式的消息系统,使用Scala编写,它以可水平扩展和高吞吐率而被广泛使用.目前越来越多的开源分布式处理系统如Cloudera.Apache Storm.Spa ...

  10. pdfcrop不能使用

    最近,用到了pdfcrop,用来去除pdf中空白的边. 但是使用pdfcrop --margins 0  *.pdf 后,给出了错误: Error: pdfcrop cannot call ghost ...