题目链接

大意:

求凸包的面积。

#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. this.parentMenu.dataRecord.data.testID的作用

    在JS里,有个this.parentMenu.dataRecord.data.XXID的方法,这个方法一般都是用来加载某个控件到一个面板或控件上的.如: loaddata(this.parentMen ...

  2. sessionStorage和localStorage之间的差别

    <!DOCTYPE html><html> <head lang="en"> <meta charset="utf-8" ...

  3. Python核心编程读笔 6: 映射和集合类型

    第七章 映射和集合能力 一 字典(python中唯一的映射类型) 1 基本 创建和赋值: 正常创建:>>>dict = {'name':'earth', 'port':80} 用工厂 ...

  4. VMWARE使用问题

    因为一些原因创建的两个虚拟机出问题了,然而里面还放了好多东西呢不想就这样删掉,就抱着试一试的心态看能不能恢复(结果真能恢复). 这里使用的方法是VMware虚拟机配置文件(.vmx)损坏修复 在这过程 ...

  5. php7 install memcache extension

    #download source code package from git $ git clone https://github.com/websupport-sk/pecl-memcache.gi ...

  6. Linux学习之route

    Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或 ...

  7. zabbix监控服务器部署

    1.服务器安装lamp环境 [root@monitor ~]# yum  install gcc gcc-c++ autoconf httpd php mysql mysql-server php-m ...

  8. Swift 基本基本运算符

    Swift 1,赋值运算符 Swift赋值表达式是没有值的,不支持连续赋值. 2,算术运算符 除数可为0 var f=1/0.0 求余的结果的正负取决于被除数 3,溢出运算符* 根据二进制来进行计算 ...

  9. myeclipse 保存时自动格式化代码

    windows -> preferences -> Java -> Editor -> Save Actions... 这就可以用到很多功能了,可以自己定义一些个保存后要处理的 ...

  10. python递归函数下不能正常使用yield

    # -*- coding:utf-8 -*- import os import time file_list = [] def findFile(path): listFile = os.listdi ...