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 ...
随机推荐
- GIT问题(二)——add报错
- 深入理解Java类加载器(ClassLoader) (转)
转自: http://blog.csdn.net/javazejian/article/details/73413292 关联文章: 深入理解Java类型信息(Class对象)与反射机制 深入理解Ja ...
- Python之并发编程-多进程
目录 一.multiprocessiong模块介绍 二.Process类的介绍 三.进一步介绍(守护进程.锁.队列.管道.事件等) 1.守护进程 2.锁(同步锁.互斥锁) 3.信号量(了解) 4.队列 ...
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)的解决
在用爬虫爬取网络小说的时候出现该问题. 估计是字符格式转换格式的错误. 暂时无法解决,搜索了其他博主的解决方案. 以下两个方案靠谱: <一>适用于全篇 import sys default ...
- [buaa-SE-2017]个人作业-Week2
个人作业-Week2 一.代码复审Checklist 1.概要部分 1.1 代码能符合需求和规格说明么? 本次作业的需求可以分成基本的功能实现和大规模数据下程序的健壮性,以及少量的异常处理能力,也就是 ...
- 20172308 实验一《Java开发环境的熟悉》实验报告
20172308 2017-2018-2 <程序设计与数据结构>实验1报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 周亚杰 学号:20172308 实验教师:王 ...
- Java script 的dom编程
实例1: </head> <body> <div id="div1"> <p id="p1">这是一个段落< ...
- 项目冲刺Beta第二篇博客
Beta版本冲刺计划安排 1.当天站立式会议照片: 2.工作分工: 团队成员 分工 张洪滨060 排行榜界面美化 陈敬轩059 注册成功界面美化 黄兴067 登录界面美化 林国梽068 答题界 ...
- NTP同步网络时间
为什么要同步网络时间呢,这是由于树莓派没有RTC和后备电池,不能像PC机那样关机之后仍可以走时. NTP对时步骤: 1 安装ntpdate sudo apt-get install ntpdate s ...
- boolean类型的按位或||和|的区别
boolean类型既可以使用&&和||做逻辑运算,也可以使用&和|做逻辑运算,但前者是经过优化的(执行短路运算),后者未优化. 以下代码验证: 逻辑或|| public cla ...