I - Cows
来源 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的更多相关文章
- [LeetCode] Bulls and Cows 公母牛游戏
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
- LeetCode 299 Bulls and Cows
Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...
- [Leetcode] Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...
- POJ2186 Popular Cows [强连通分量|缩点]
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31241 Accepted: 12691 De ...
- Poj2186Popular Cows
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31533 Accepted: 12817 De ...
- [poj2182] Lost Cows (线段树)
线段树 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacula ...
- 【POJ3621】Sightseeing Cows
Sightseeing Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8331 Accepted: 2791 ...
随机推荐
- 基于Python3.6使用Django框架连接mysql数据库的驱动模块安装解决办法
解决办法1 使用PyMySQL模块,直接使用pip install pymysql即可. 参考文章:https://www.cnblogs.com/wcwnina/p/8719482.html 原文内 ...
- ANTLR flex/bison
https://stackoverflow.com/questions/29971097/how-to-create-ast-with-antlr4 这个很值得仔细看 https://github.c ...
- 【C#】C#中的属性与字段
目录结构: contents structure [+] 属性和字段的区别 无参属性 自动实现的属性 对象和集合初始化器 匿名类型 System.Tuple类型 有参属性 属性的可访问性 在这篇文章中 ...
- Boost中的智能指针(转)
这篇文章主要介绍 boost中的智能指针的使用.(转自:http://www.cnblogs.com/sld666666/archive/2010/12/16/1908265.html) 内存管理是一 ...
- 【Vegas原创】SQL Server 只安装客户端的方法
只安装管理工具
- shell函数【参数传递及输入输出】&内置函数
Linux——shell脚本基础3:shell函数[参数传递及输入输出]&内置函数 函数定义 1 退出状态 1 参数传递 2 标准IO 2 脚本调试 2 AND&OR 3 内置命令补充 ...
- 一次性将多个文件夹批处理压缩成多个.rar
超级简单.不用自己写.bat批处理. 1. 打开winrar,选中所有要压缩的文件夹 2. 菜单->commands->add files to achive 3. 选中Files tab ...
- NodeJS的url验证库模块url-valid
这是我10月份做的项目其中的一个部件,主要用于url检验的. 我们知道Javascript做url检验,通常是使用正则表达式来判定,其格式是否正确,例如: /^https?:\/\//.test(ur ...
- git push origin master和git push有什么区别?
1.master是主分支,还可以建一些其他的分支用于开发.2.git push origin master的意思就是上传本地当前分支代码到master分支.git push是上传本地所有分支代码到远程 ...
- 批量 kill mysql 线程
时常有一些烂sql跑在数据库里,我们要进行kill,避免影响拖垮数据库. mysql> show processlist; +----+------+---------------------+ ...