题目链接

大意:

求凸包的面积。

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = ;
struct point
{
int x,y;
};
point a[maxn];
int st[maxn], top;
int cross(point p0,point p1,point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double dis(point p1,point p2)
{
return sqrt((double)(p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
bool cmp(point p1,point p2)
{
int tmp=cross(a[],p1,p2);
if(tmp>) return true;
else if(tmp==&&dis(a[],p1)<dis(a[],p2)) return true;
else return false;
}
void init(int n)
{
int i,k;
point p0;
scanf("%d%d",&a[].x,&a[].y);
p0.x=a[].x;
p0.y=a[].y;
k=;
for(i=;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
if( (p0.y>a[i].y) || ((p0.y==a[i].y)&&(p0.x>a[i].x)) )
{
p0.x=a[i].x;
p0.y=a[i].y;
k=i;
}
}
a[k]=a[];
a[]=p0; sort(a+,a+n,cmp);
}
void graham(int n)
{
int i;
if(n==) {top=;st[]=;}
if(n==)
{
top=;
st[]=;
st[]=;
}
if(n>)
{
for(i=;i<=;i++) st[i]=i;
top=; for(i=;i<n;i++)
{
while(top>&&cross(a[st[top-]],a[st[top]],a[i])<=) top--;
top++;
st[top]=i;
}
}
}
int main()
{
int n, r;
while(cin>>n) {
init(n);
graham(n);
double ans = ;
for(int i = ; i<top; i++) {
ans += (a[st[i]].x*a[st[i+]].y-a[st[i]].y*a[st[i+]].x);
}
ans += a[st[top]].x*a[st[]].y-a[st[top]].y*a[st[]].x;
ans /= ;
cout<<int(ans/)<<endl;
}
return ;
}

poj 3348 Cows 求凸包面积的更多相关文章

  1. POJ 3348 Cows(凸包+多边形面积)

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

  2. 2018.07.03 POJ 3348 Cows(凸包)

    Cows Time Limit: 2000MS Memory Limit: 65536K Description Your friend to the south is interested in b ...

  3. poj 3348:Cows(计算几何,求凸包面积)

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6199   Accepted: 2822 Description ...

  4. POJ 3348 - Cows 凸包面积

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

  5. 【UVA10652】Board Wrapping(求凸包面积)

    点此看题面 大致题意: 告诉你若干个矩形的重心坐标.长.宽和相对\(y\)轴的偏转角度,求矩形面积和与能围住这些矩形的最小凸包面积之比. 矩形面积和 这应该是比较好求的吧. 已经给了你长和宽,直接乘起 ...

  6. poj3348(求凸包面积)

    题目链接:https://vjudge.net/problem/POJ-3348 题意:转换题意后即是求凸包的面积. 思路: 套模板,求凸包面积即转换为多个三角形面积之和,用叉积求,然后除2,因为本题 ...

  7. POJ 3348 Cows 凸包 求面积

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

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

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

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

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

随机推荐

  1. JavaScript的一些小用法

    1.if问题: var a="this test"; if (a == "this test") //这样写的时候执行不下去了,不知为什么. 修改: var a ...

  2. create a (VSTO) Office 2007 add-in using VS 2012?

    You can get VS 2012 working with Office 2007. First create an Outlook 2010 Add-In and modify the pro ...

  3. TCP/IP协议族

    1.TCP(传输控制协议)/IP(网际协议)协议族是一个网络通讯模型,以及一整个网络传输协议家族,为互联网的基础通讯架构. TCP/IP四层协议的表示方法: 2.TCP/IP参考模型映射到OSI模型: ...

  4. Ubuntu 14.04安装Sogou输入法

    在http://pinyin.sogou.com/linux/?r=pinyin页面可下载对应的的deb包.在http://pinyin.sogou.com/linux/help.php页面有搜狗输入 ...

  5. iOS程序启动原理(简单)

    1.执行main -> 执行UIApplicationMain UIApplicationMain底层实现 1.创建UIApplication对象 2.创建UIApplication代理对象 3 ...

  6. HighlightingSystem插件使用(边缘发光)

    插件链接: http://pan.baidu.com/s/1dFwkaTr 密码: nw2c 导入Unity里面可能会报错,不过没关系,直接注释掉就可以了,我用的是Unity5.1的版本 可以看到如下 ...

  7. Python核心编程读笔 12:OOP

    第13章 面向对象编程 一.基本概念 1.object类是所有类的基类,如果你的类没有继承任何其他父类,object 将作为默认的父类. 2.python创建实例时无需new: myFirstObje ...

  8. JavaWeb核心编程之(三.2)Servlet配置

    Servlet配置 1.配置Serlvet加载时机 2.配置多映射 配置加载时机 新建项目config->创建包com.xiaoan.config->创建类FirstServlet imp ...

  9. 浏览器间bug

    转自:http://www.cnblogs.com/yexiaochai/archive/2013/06/10/3130632.html 1.IE7的bug 就是z-index需要依赖其父元素的z-i ...

  10. js previousSibling兼容使用方法

    使用previousSibling的时候发现当前元素跟上一个元素之间有空格就不获取不到对象, 查资料才知道除了ie外js的previousSibling获取的对象包括空格! 兼容方法如下: funct ...