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 ...
随机推荐
- 《杜增强讲Unity之Tanks坦克大战》5-子弹
5 子弹 本节的任务是创建子弹的Prefab image 首先从Model/Shell找到子弹的模型,拖入Hierarchy中,添加刚体组件,所有属性默认值. 添加Capsule Collider ...
- 学习笔记 | Github
Github教程 \(Github\)是个好东西QwQ 存代码不用U盘爸爸妈妈再也不用担心我的U盘弄丢没有备份啦! 创建github账号 创建仓库 输入命令 git clone https://git ...
- linux磁盘扩容日志
//针对ext4文件格式的操作系统(如CentOS6):// umount /dev/vdb e2fsck -f /dev/vdb resize2fs /dev/vdb mount /dev/vdb ...
- Django之自带认证
自带登录实例 {% extends "layout/base.html" %} // 所有link {% block body %} <div id="contai ...
- java实验2实验报告(20135232王玥)
实验二 Java面向对象程序设计 一.实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解 ...
- 课堂讨论—Alpha版总结会议
我们在课堂上针对第一阶段冲刺过程中存在的问题,展开了激烈的讨论,并投票选出需要改进的最主要三个问题. 有图有真相:
- git 的认识
简单说,三个概念:远程仓库.本地仓库.本地工作目录.clone是从远程仓库上down下本地仓库+工作目录:本地仓库就是工作目录里.git这个目录commit是把工作目录的修改提交给本地仓库pull把远 ...
- python learning OOP2.py
class Student(object): pass s = Student() s.name = 'Chang' # 给一个实例动态绑定一个属性 print(s.name) def set_age ...
- p4factory下 targets/basic_rout
p4factory/targets/basic_routing/p4src代码解读 headers.p4 header_type ethernet_t { fields { dstAddr : 48; ...
- 基于windowsphone7的控制ppt播放
最近突然想起了一个学长的一个利用手机控制ppt播放的一个创意,并想将其在windows phone7上实现一下. 经过几天的努力已经可以控制ppt的播放,暂停,上一张,下一张了,并且电脑会将当前ppt ...