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,然后就得到答案,直接上模板了. ...
随机推荐
- [转]行者,一念一生,成功的背后!(给所有IT人)
成功的背后,有着许多不为人知的故事,而正是这些夹杂着泪水和汗水的过去,才成就了一个个走向成功的普通人. 凌晨两点半,早 已习惯了一个人坐在电脑前的我,望着屏幕,任思绪在暗夜的包容下静静流淌,时光仿佛又 ...
- 全景视频外包团队:U3D全景漫游(二)
单击Ambient Light,如下 调整为 即可设置完成 14.设置第一人称浏览 删除场景中Main Camera 将Project区域的Standard Assets下的Prefabs下的Firs ...
- Java中的代理模式
代理模式在Java Web的框架中经常使用到.比如说在对数据库的访问中,核心功能是对数据库的增删改查,而连接数据库.处理事务等功能我们在开发中也要考虑到.所以我们将数据库的CRUD抽象到接口中,然后实 ...
- iOS 中如何将View设置为圆角的矩形?
今天刚好需要添加一个圆角的view. 必须先导入头文件. #import <QuartzCore/QuartzCore.h> bgView.layer.cornerRadius = cor ...
- day7-socket
socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. socket起源于Un ...
- OS X 禁止Android File Transfer自动启动
操作步骤 关闭Android File Manager 在Activity Manager中退出Android File Manager Agent进程 在Applications中,将Android ...
- tinyxml学习5
读取和设置xml配置文件是最常用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,因为它的API接口和Java的十分类似,面向对象性很好. TinyXML是一个开源的解 ...
- VBS数组
定义一个数组: dim a(3).这里要注意在VBS里面数组不像其他的例如C,C#,JAVA等数组用[]作为数组标志.VBS采用的是().还需要注意的是,这里定义的数组包含a(0),a(1),a(2) ...
- log4j按级别输出日志文件
log4j.properties: BASE_DIR= /home/admin/preprocess-tmc-city/logs log4j.rootLogger=debug,stdout,debug ...
- Java分布式Socket监控项目思考
内容说明 一项课程作业Java编写Socket长连接监控分布式终端,并将终端状态写入数据库供前端查询 基础:c++/Posix/APUE/Mysql&sqlite 核心内容:Socket/线程 ...