求凸包面积。求结果后不用加绝对值,这是BBS()排序决定的。

//Ps 熟练了template <class T>之后用起来真心方便= =

//POJ 3348
//凸包面积
//1A 2016-10-15 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#define MAXN (10000 + 10) struct point{
int x, y;
point(){}
point(int X, int Y): x(X), y(Y){}
friend int operator ^ (const point &p1, const point &p2){
return p1.x * p2.y - p1.y * p2.x;
}
friend point operator >> (const point &p1, const point &p2){
return point(p2.x - p1.x, p2.y - p1.y);
}
friend bool operator < (const point &p1, const point &p2){
return (p1.x < p2.x)||(p1.x == p2.x)&&(p1.y < p2.y);
}
}pt[MAXN]; template <class T>
void swap(T &a, T & b){
T t = a;
a = b;
b = t;
} template <class T>
void BBS(T a[], int n){
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++)
if (a[i] < a[j]) swap(a[j], a[i]);
} double convex_hull(point p[], int n){
int cur = 0;
double area = 0;
BBS(p, n);
while (1){
int tmp = - 1;
for (int i = 0; i < n; i++){
if (cur != i){
if (!(tmp + 1)||((p[cur] >> p[i]) ^ (p[cur] >> p[tmp])) > 0)
tmp = i;
}
}
if (tmp + 1){
area += p[cur] ^ p[tmp];
}
if (!tmp||!(tmp + 1)) return area / 2;
cur = tmp;
}
} int main(){
int n;
freopen("fin.c", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; i++){
scanf("%d%d", &pt[i].x, &pt[i].y);
}
printf("%d\n", int(convex_hull(pt, n)/50));
}

POJ 3348 - Cows 凸包面积的更多相关文章

  1. POJ 3348 Cows [凸包 面积]

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

  2. poj 3348 Cow 凸包面积

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

  3. POJ 3348 Cows 凸包 求面积

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

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

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

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

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

  6. POJ 3348 Cows | 凸包模板题

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

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

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

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

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

  9. POJ 3348 Cows

    题目大意: 给你n棵树,可以用这n棵树围一个圈,然后在圈里面可以养牛,每个牛需要50平方米的空间,问最多可以养多少牛? 其实就是求一个凸包,计算凸包面积,然后除以50,然后就得到答案,直接上模板了. ...

随机推荐

  1. Mac OS X 上Lua的安装方法

    先在Mac OS的终端查询下本机是否已安装Lua Last login: Thu Jul 10 07:54:48 on ttys000 keshans-Mac-mini:~ keshan$ lua - ...

  2. Mac下Nginx环境配置

    环境信息: Mac OS X 10.11.1 Homebrew  0.9.5 正文 一.安装 Nginx 终端执行: brew search nginx brew install nginx 当前版本 ...

  3. Centreon 监控报警

    1.系统更新:yum update 2.安装组件:yum install -y httpd php-pear php php-mysql php-gd php-ldap php-xml php-mbs ...

  4. Cellmap 基站查询 For Pc

    cellmap for pc 6.2.8.3.0.9 在线版本 更新日期:2017年1月5日 下载地址:<地址一> 主页:www.cellmap.cn 特别声明:本软件不能手机定位.谨防受 ...

  5. SSIS 基础知识

    微软 BI 系列随笔 - SSIS 2012 基础 - SSIS 基础知识 SSIS 介绍 SSIS - SQL Server Integration Services 是用于实现企业级数据集成和数据 ...

  6. H5课程大纲

    K1模块课程: 课程模块 课程阶段 课程内容 K1 模块 第1阶段 认识前端开发 环境配置.使用标签的分类.写法及使用规范CSS样式的使用.各类常见样式Photoshop使用16大常用样式盒模型.语义 ...

  7. Angular(1)

    1.设计原则 1.YAGNI  不要把未来需求引入当前工程   2.KISS  keep it simple and stupid  语义化标记 合理注释 符合规定的命名 3.DRY(don't re ...

  8. [FFmpeg] ffmpeg参数详解

    ffmpeg 参数语法 ffmpeg [[options][`-i' input_file]]... {[options] output_file}... 如果没有输入文件,那么视音频捕捉就会起作用. ...

  9. UNIX网络编程-基本API介绍(一)

    1.基本结构 大多数套接口函数都需要一个指向套接口地址结构的指针作为参数.每个协议族都定义它自己的套接口地址结构.这些结构的名字均以“sockaddr_”开头,并以对应每个协议族的唯一后缀结束. 1. ...

  10. Archlinux KDE 添加中文语言包

    From: https://wiki.archlinux.org/index.php/KDE_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%29#.E8.AF.AD. ...