POJ 3348 - Cows 凸包面积
求凸包面积。求结果后不用加绝对值,这是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 凸包面积的更多相关文章
- POJ 3348 Cows [凸包 面积]
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9022 Accepted: 3992 Description ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- POJ 3348 Cows (凸包模板+凸包面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- POJ 3348 Cows | 凸包模板题
题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...
- POJ 3348 Cows | 凸包——童年的回忆(误)
想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...
- poj 3348:Cows(计算几何,求凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6199 Accepted: 2822 Description ...
- POJ 3348 Cows
题目大意: 给你n棵树,可以用这n棵树围一个圈,然后在圈里面可以养牛,每个牛需要50平方米的空间,问最多可以养多少牛? 其实就是求一个凸包,计算凸包面积,然后除以50,然后就得到答案,直接上模板了. ...
随机推荐
- Ubuntu下两个gcc版本切换
Ubuntu系统使用的gcc版本随着发布版本的不同而不同,在编译Android系统时不同的版本推荐用不同的gcc去编译,那么可不可以改变系统的gcc来适应android编译环境的需求呢?答案是可以的. ...
- C#多线程网摘 2
C#中,可以使用Thread类来处理(包含创建,启动,挂起,恢复,终止等操作)线程.本文将介绍如何使用Thread类来创建与启动新线程. Thread类类位于System.Threading命名空间中 ...
- JSBinding / Code Snippets
new a gameobject & overloaded methds var go1 = new UnityEngine.GameObject.ctor(); var go2 = new ...
- VC_MFC水波纹控件,开源
代码和效果图: https://github.com/wjx0912/MfcWaterEffect 集成以下5个文件即可: watereffect\DIB.hwatereffect\DIB.cppwa ...
- AutoFac使用~IOC容器(DIP,IOC,DI)
#cnblogs_post_body h1 { background-color: #A5A5A5; color: white; padding: 5px } Autofac一款IOC容器,据说比Sp ...
- 高度平衡的二叉搜索树(AVL树)
AVL树的基本概念 AVL树是一种高度平衡的(height balanced)二叉搜索树:对每一个结点x,x的左子树与右子树的高度差(平衡因子)至多为1. 有人也许要问:为什么要有AVL树呢?它有什么 ...
- view
把view添加到某个视图的虾面 [self.superview insertSubview:smallCircle belowSubview:self]; // 返回两个数的根 return sqrt ...
- FW开发代码规范---小任性(1)
---恢复内容开始--- 使代码容易理解的方法无非是准确地注释和增强代码一致性. 一个好的准确的注释让代码容易理解是显然的.而代码的一致性,使编程风格统一,容易在内部形成一些共识.习惯用语和模式. 一 ...
- Linux 日志服务器 rsyslog
预先需要httpd.php.mysql,yum方式安装.创建数据库: yum install rsyslog rsyslog-mysql cd /usr/share/doc/rsyslog-mysql ...
- Oracle时间戳 与时间之间的相互转换
Unix时间戳记是从'1970-01-01 00:00:00'GMT开始的秒数,表现为整数型. Oracle中的时间是Date型,以下函数提供了两种时间转换的Oracle函数 (1)从Unix时间戳记 ...