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 ...
随机推荐
- C# ConcurrentStack实现
我们通过C# Queue 和Stack的实现知道Stack是依靠数组实现的,那么ConcurrentStack的栈又是如何实现的了,然后它的线程安全又是怎么做到的了? 来看看其code吧 public ...
- html-透明背景层
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java 终于有 Lambda 表达式啦~Java 8 语言变化——Lambda 表达式和接口类更改【转载】
原文地址 en cn 下载 Demo Java™ 8 包含一些重要的新的语言功能,为您提供了构建程序的更简单方式.Lambda 表达式 为内联代码块定义一种新语法,其灵活性与匿名内部类一样,但样板文件 ...
- spring cloud配置中心属性加密处理
在现实的场景里,我们会在配置中心配置很多中间件的账号密码(通常都是读写账号),如果采用明文存储将会有很大的风险导致账号泄露,解决方案: http://blog.didispace.com/spring ...
- 5.翻译系列:EF 6中数据库的初始化(EF 6 Code-First 系列)
原文地址:http://www.entityframeworktutorial.net/code-first/database-initialization-in-code-first.aspx EF ...
- Java list对象列表排序 实例
package com.test; public class Bean { private String name; private int priority; public String getNa ...
- Ubuntu 13.10 解决虚拟机摄像头无法使用问题
前段时间使用的是Ubuntu 13.04,使用virtualbox虚拟机 4.2版,虚拟机里边装的Windows 7和Windows8.1均无法使用摄像头.只要在USB设备中选上了摄像头,虚拟机系统准 ...
- 图解ByteBuffer
https://www.cnblogs.com/ruber/p/6857159.html https://www.e-learn.cn/content/qita/750752 https://blog ...
- 【XMPP】XMPP类型
1.ConnectionConfiguration 作为用于与XMPP服务建立连接的配置.它能配置:连接是否使用TLS,SASL加密. 包含内嵌类:ConnectionConfiguration.Se ...
- JAVA(五)反射机制/Annotation
成鹏致远 | lcw.cnblog.com |2014-02-04 反射机制 1.认识Class类 在正常情况下,必须知道一个类的完整路径之后才可以实例化对象,但是在 java中也允许通过一个对象来找 ...