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.

题目大意:给n个点,求凸包,然后求这个凸包的面积。

思路:跟题目大意一样……

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; const int MAXN = ;
const double EPS = 1e-;
const double PI = acos(-1.0);//3.14159265358979323846 inline int sgn(double x) {
return (x > EPS) - (x < -EPS);
} struct Point {
double x, y;
Point() {}
Point(double x, double y): x(x), y(y) {}
void read() {
scanf("%lf%lf", &x, &y);
}
bool operator == (const Point &rhs) const {
return sgn(x - rhs.x) == && sgn(y - rhs.y) == ;
}
bool operator < (const Point &rhs) const {
if(y != rhs.y) return y < rhs.y;
return x < rhs.x;
}
Point operator + (const Point &rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
Point operator * (const int &b) const {
return Point(x * b, y * b);
}
Point operator / (const int &b) const {
return Point(x / b, y / b);
}
double length() const {
return sqrt(x * x + y * y);
}
Point unit() const {
return *this / length();
}
};
typedef Point Vector; double dist(const Point &a, const Point &b) {
return (a - b).length();
} double cross(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
}
//ret >= 0 means turn left
double cross(const Point &sp, const Point &ed, const Point &op) {
return sgn(cross(sp - op, ed - op));
} double area(const Point& a, const Point &b, const Point &c) {
return fabs(cross(a - c, b - c)) / ;
} struct Seg {
Point st, ed;
Seg() {}
Seg(Point st, Point ed): st(st), ed(ed) {}
void read() {
st.read(); ed.read();
}
};
typedef Seg Line; bool isOnSeg(const Seg &s, const Point &p) {
return (p == s.st || p == s.ed) ||
(((p.x - s.st.x) * (p.x - s.ed.x) < ||
(p.y - s.st.y) * (p.y - s.ed.y) < ) &&
sgn(cross(s.ed, p, s.st) == ));
} bool isIntersected(const Point &s1, const Point &e1, const Point &s2, const Point &e2) {
return (max(s1.x, e1.x) >= min(s2.x, e2.x)) &&
(max(s2.x, e2.x) >= min(s1.x, e1.x)) &&
(max(s1.y, e1.y) >= min(s2.y, e2.y)) &&
(max(s2.y, e2.y) >= min(s1.y, e1.y)) &&
(cross(s2, e1, s1) * cross(e1, e2, s1) >= ) &&
(cross(s1, e2, s2) * cross(e2, e1, s2) >= );
} bool isIntersected(const Seg &a, const Seg &b) {
return isIntersected(a.st, a.ed, b.st, b.ed);
} bool isParallel(const Seg &a, const Seg &b) {
return sgn(cross(a.ed - a.st, b.ed - b.st)) == ;
} //return Ax + By + C =0 's A, B, C
void Coefficient(const Line &L, double &A, double &B, double &C) {
A = L.ed.y - L.st.y;
B = L.st.x - L.ed.x;
C = L.ed.x * L.st.y - L.st.x * L.ed.y;
} Point intersection(const Line &a, const Line &b) {
double A1, B1, C1;
double A2, B2, C2;
Coefficient(a, A1, B1, C1);
Coefficient(b, A2, B2, C2);
Point I;
I.x = - (B2 * C1 - B1 * C2) / (A1 * B2 - A2 * B1);
I.y = (A2 * C1 - A1 * C2) / (A1 * B2 - A2 * B1);
return I;
} bool isEqual(const Line &a, const Line &b) {
double A1, B1, C1;
double A2, B2, C2;
Coefficient(a, A1, B1, C1);
Coefficient(b, A2, B2, C2);
return sgn(A1 * B2 - A2 * B1) == && sgn(A1 * C2 - A2 * C1) == && sgn(B1 * C2 - B2 * C1) == ;
} struct Poly {
int n;
Point p[MAXN];//p[n] = p[0]
void init(Point *pp, int nn) {
n = nn;
for(int i = ; i < n; ++i) p[i] = pp[i];
p[n] = p[];
}
double area() {
if(n < ) return ;
double s = p[].y * (p[n - ].x - p[].x);
for(int i = ; i < n; ++i)
s += p[i].y * (p[i - ].x - p[i + ].x);
return s / ;
}
}; void Graham_scan(Point *p, int n, int *stk, int &top) {//stk[0] = stk[top]
sort(p, p + n);
top = ;
stk[] = ; stk[] = ;
for(int i = ; i < n; ++i) {
while(top && cross(p[i], p[stk[top]], p[stk[top - ]]) >= ) --top;
stk[++top] = i;
}
int len = top;
stk[++top] = n - ;
for(int i = n - ; i >= ; --i) {
while(top != len && cross(p[i], p[stk[top]], p[stk[top - ]]) >= ) --top;
stk[++top] = i;
}
} /*******************************************************************************************/ Point p[MAXN];
Poly poly;
int stk[MAXN], top;
int n, T; int solve() {
poly.n = top;
for(int i = ; i <= top; ++i) poly.p[i] = p[stk[i]];
double ret = poly.area() + EPS;
return int(ret / );
} int main() {
scanf("%d", &n);
for(int i = ; i < n; ++i) p[i].read();
Graham_scan(p, n, stk, top);
printf("%d\n", solve());
}

POJ 3348 Cows(凸包+多边形面积)的更多相关文章

  1. POJ 3348 Cows 凸包 求面积

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

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

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

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

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

  4. POJ 3348 - Cows 凸包面积

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

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

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

  6. POJ 3348:Cows 凸包+多边形面积

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7739   Accepted: 3507 Description ...

  7. POJ 3348 Cows [凸包 面积]

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

  8. POJ 3348 Cows | 凸包模板题

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

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

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

  10. poj 3348 Cow 凸包面积

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

随机推荐

  1. iOS之safari调试iOS app web页面

    Overview 当下移动端开发过程中大量使用前段H5.js等等技术,而这些web页面的调试在Xcode控制台中不太明了,经常我们移动app运行了就是方法,但是不能显示响应的效果,这时候或许就是已经报 ...

  2. windows用交互式命令执行python程序

    1.进入cmd命令 windows+r2.进入盘符,eg:E:3.使用dir命令查看当前文件夹下的所有目录4.使用绝对路径或者相对路径和cd命令直接进入想要到达的文件夹目录(或者使用cd命令一步一步达 ...

  3. mariadb或者mysql忘记root密码

    windows======================net stop mysql #先停止mysql或者在服务管理里面停止 直接打开Windows的命令行(CMD)窗口(以管理员身份运行),输入 ...

  4. centos总结linux下svn安装与使用

    一.安装篇 centos下yum安装 yum install subversion 查看安装是否成功: svnserve --version 查看安装内容与位置 rpm -ql subversion ...

  5. 解决 LLVM 错误提示 may only occur zero or one times!

    使用 LLVM 混淆器添加参数进行编译提示如下错误:clang (LLVM option parsing): for the -bcf option: may only occur zero or o ...

  6. Git命令中日常不注意又很重要的坑

    引言   简单聊一下Git的常用命令和概念,其中很多命令开发者在使用时用法不当导致出现很多问题:   比如,新创建的分支没有追踪想要追踪的分支,很想看到版本提交的内容   以下是觉得比较好用并且完整的 ...

  7. Python2和Python3

    1. 字符编码 1.1. Python2默认为ACSII编码 1.2. Python3为Unicode 2. Unicode和UTF8和GBK编码的关系 utf8:中文3字节              ...

  8. python网络编程之进程

    一.什么是进程 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在早期面向进程设计的计算机结构中,进程是程序的基本执行实 ...

  9. 阿里云 Debian 9.2 安装 Java Web 环境

    CentOS 源内包太旧,和本地开发环境不兼容的地方太多 系统配置 更新数据库与软件包 # apt-get update && apt-get -y upgrade 提示是否保留本地已 ...

  10. Map,Hashmap,LinkedHashMap,Hashtable,TreeMap

    java为数据结构中的映射定义了一个接口java.util.Map;它有四个实现类,分别是HashMap Hashtable LinkedHashMap 和TreeMap. Map主要用于存储健值对, ...