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 ...
随机推荐
- 从源码编译InfluxDB
操作系统 : CentOS7.3.1611_x64 go语言版本:1.8.3 linux/amd64 InfluxDB版本:1.1.0 go语言安装参考: http://www.cnblogs.com ...
- settings.xml配置详解
简单值 一半顶层settings元素是简单值,它们表示的一系列值可以配置Maven的核心行为:settings.xml中的简单顶层元素 < settings xmlns="http:/ ...
- 如何将Ubuntu Server 12.04 升级到 Ubuntu Server 14.04 LTS
升级Ubuntu 12.04到Ubuntu 14.04方法如下: 步骤一:在终端中运行下面的命令,它将安装所有的升级包.$ sudo apt-get update && sudo ap ...
- Axure RP for Mac(网站交互式原型设计工具)破解版安装
1.软件简介 Axure RP 是 macOS 系统上一款最知名和最强大的原型设计工具,增加了大量新的特性,如应用多个动画,并同一时间运行一个小部件,如褪色,同时移动等,而且具有全新的图标和界面 ...
- Redis资料整理
1.Redis命令參考中文简体版. 2.java操作redis.jedis使用api 3.Redis学习笔记. 4.浅谈Redis数据库的键值设计 5.Redis资料汇总专题 6.MongoDB资料汇 ...
- 拯救安卓手机的数据(无法进入系统只能打开recovery)
这里不得不赞一个谷歌的开放,如果不是这样读取数据就很糟糕了,记得一千带着我的mac本子到苹果店,那个所谓的“天才”就说苹果的数据无法读取,我了个艹,为了避免丢失你必须得准备一个TM.好了废话不多说,进 ...
- Atitit Uncaught (in promise) SyntaxError Unexpected token < in JSON at position 0
Atitit Uncaught (in promise) SyntaxError Unexpected token < in JSON at position 0 Uncaught (in ...
- vue中使用localstorage
1.store.js(读取写入到localstorage) const STORAGE_KEY="todos-vuejs" export default{ fetch(){ ret ...
- SoapUI5.0创建WebService接口模拟服务端(转)
转载自:https://blog.csdn.net/a19881029/article/details/26348627 使用SoapUI创建WebService接口模拟服务端需要接口描述文件 Mat ...
- 【九天教您南方cass 9.1】 03 编码法绘制地形图
同学们大家好,欢迎收看由老王测量上班记出品的cass9.1视频课程 我是本节课主讲老师九天. 测量空间的[九天教您南方cass]专栏是九天老师专门开设cass免费教学班.希望能帮助那些刚入行的同学,并 ...