POJ 3348 Cows | 凸包——童年的回忆(误)
想当年……还是邱神给我讲的凸包来着……
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define eps 0.000000001
#define enter putchar('\n')
#define space putchar(' ')
using namespace std;
typedef long long ll;
template <class T>
void read(T &x){
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-') op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op) x = -x;
}
template <class T>
void write(T x){
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar('0' + x % 10);
}
const int N = 10005, INF = 0x3f3f3f3f;
int n, top, ans;
struct point {
int x, y;
point(){}
point(int _x, int _y): x(_x), y(_y){}
point operator - (point b) const{
return point(x - b.x, y - b.y);
}
int operator * (point b){
return x * b.y - y * b.x;
}
int norm(){
return x * x + y * y;
}
} p[N], stk[N], root;
bool operator < (const point &a, const point &b){
int det = (a - root) * (b - root);
if(det) return det > 0;
return (a - root).norm() < (b - root).norm();
}
void graham(){
int pos = 0;
root.x = root.y = INF;
for(int i = 1; i <= n; i++)
if(p[i].x < root.x || (p[i].x == root.x && p[i].y < root.y))
root = p[i], pos = i;
if(pos != 1) swap(p[pos], p[1]);
sort(p + 2, p + n + 1);
stk[top = 1] = root;
for(int i = 2; i <= n; i++){
while(top >= 2 && (stk[top] - stk[top - 1]) * (p[i] - stk[top - 1]) < 0) top--;
stk[++top] = p[i];
}
}
void getarea(){
stk[top + 1] = stk[1];
for(int i = 1; i <= top; i++)
ans += stk[i] * stk[i + 1];
}
int main(){
read(n);
for(int i = 1; i <= n; i++)
read(p[i].x), read(p[i].y);
graham();
getarea();
write(ans / 2 / 50), enter;
return 0;
}
POJ 3348 Cows | 凸包——童年的回忆(误)的更多相关文章
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- 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 [凸包 面积]
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9022 Accepted: 3992 Description ...
- POJ 3348 Cows | 凸包模板题
题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- 2018.07.03 POJ 3348 Cows(凸包)
Cows Time Limit: 2000MS Memory Limit: 65536K Description Your friend to the south is interested in b ...
- poj 3348:Cows(计算几何,求凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6199 Accepted: 2822 Description ...
随机推荐
- Netty 粘包/拆包应用案例及解决方案分析
熟悉TCP变成的可以知道,无论是客户端还是服务端,但我们读取或者发送消息的时候,都需要考虑TCP底层粘包/拆包机制,下面我们先看一下TCP 粘包/拆包和基础知识,然后模拟一个没有考虑TCP粘包/拆包导 ...
- Netty源码分析第5章(ByteBuf)---->第1节: AbstractByteBuf
Netty源码分析第五章: ByteBuf 概述: 熟悉Nio的小伙伴应该对jdk底层byteBuffer不会陌生, 也就是字节缓冲区, 主要用于对网络底层io进行读写, 当channel中有数据时, ...
- JavaScript学习要点
Javascript相关内容 1.序列化--json - stringify() 将对象转换为字符串 - parse() 将字符串转换为对象 list=[11,22,33,44,55]; 结果:(5) ...
- python打包成exe文件
在cmd命令提示符窗口中输入pip install pyinstaller(在python3的环境下,假如不能安装的话,用pip3 install pyinstaller指令) 使用指令pyinsta ...
- python-五行红旗实现
import turtle """ 绘制五星红旗 作者:zxj 版本:1.0 """ # 绘制矩形函数 def giant(leg,hig) ...
- 04-matplotlib-柱形图
import numpy as np import matplotlib.pyplot as plt # 柱形图 # 例一 N =5 y = [15,28,10,30,25] index = np.a ...
- Android工程导入Unity3D(避坑版)
最近与各种牛逼的项目管理软件打交道,比如SourceTree,要看英文版的才看得懂,中文反而不会用!... 这篇博客适合没怎么接触过安卓的小伙伴们,网上也有很多相关的教程,但是大多都没有具体的操作或则 ...
- Nginx中server_name 参数详解
Nginx中的server_name指令主要用于配置基于名称的虚拟主机,server_name指令在接到请求后的匹配顺序分别为: 1.准确的server_name匹配,例如: server { lis ...
- CentOs6.5中安装和配置vsftp简明教程[转]
CentOs6.5中安装和配置vsftp简明教程 林涛 发表于:2017-3-17 10:10 分类:WebServer 标签: 101次 一.vsftp安装篇 复制代码代码如下: # 安装vsftp ...
- TeamWork#3,Week5,Scrum Meeting 11.4
今天我们进行了第一次Scrum Meeting,总结了最近一段时间的工作成果和经验教训,并分配了每个成员下一步的工作.网络爬虫对我们来说是一个难点,因为之前接触比较少,所以需要从头学起.我们参考了大量 ...