POJ3348:Cows——题解
http://poj.org/problem?id=3348
题目大意:用已给出的点围出面积最大的凸包,输出面积/50(向下取整)
——————————————————————————
第一道凸包?以及不知道第几次的奶牛题……
显然裸题,切了。
(那博文的意义何在?)
(呃……方便以后抄板子?)
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef double dl;
const int N=1e5+;
inline int read(){
int X=,w=;char ch=;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch))X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
struct Point{
dl x,y;
Point(dl x0=,dl y0=){x=x0,y=y0;}
}; dl dis(Point a,Point b){//求两点距离
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} typedef Point Vector;
Vector operator +(Point a,Point b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Point a,dl k){return Vector(a.x*k,a.y*k);}
Vector operator /(Point a,dl k){return Vector(a.x/k,a.y/k);} dl Dot(Vector a,Vector b){//求点积
return a.x*b.x+a.y*b.y;
}
dl Cross(Vector a,Vector b){//求叉积
return a.x*b.y-b.x*a.y;
}
dl Cross(Point sp,Point ep,Point op){//得到sp-op和ep-op的叉积
return (sp.x-op.x)*(ep.y-op.y)-(ep.x-op.x)*(sp.y-op.y);
} Point p[N],q[N];
int n,k,m;
inline bool cmp(int u,int v){
int det=Cross(p[u],p[v],p[]);
if(det!=)return det>;
return dis(p[],p[u])<dis(p[],p[v]);
}
void graham(){
int id=;
for(int i=;i<=n;i++)
if(p[i].x<p[id].x||(p[i].x==p[id].x&&p[i].y<p[id].y))
id=i;
if(id!=)swap(p[],p[id]); static int per[N];
for(int i=;i<=n;i++)per[i]=i;
sort(per+,per+n+,cmp); q[++m]=p[];
for(int i=;i<=n;i++){
int j=per[i];
while(m>=&&Cross(p[j],q[m],q[m-])>=)m--;
q[++m]=p[j];
}
return;
}
inline int area(){
int ans=;
q[].x=;q[].y=;
for(int i=;i<=m;i++)ans+=Cross(q[i],q[i%m+],q[]);
return abs(ans)/;
}
int main(){
n=read();
for(int i=;i<=n;i++)p[i].x=read(),p[i].y=read();
graham();
int ans=area()/;
printf("%d\n",ans);
return ;
}
POJ3348:Cows——题解的更多相关文章
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...
- POJ2182 Lost Cows 题解
POJ2182 Lost Cows 题解 描述 有\(N\)(\(2 <= N <= 8,000\))头母牛,每头母牛有自己的独一无二编号(\(1..N\)). 现在\(N\)头母牛站成一 ...
- POJ3348 Cows 计算几何 凸包
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ3348 题意概括 求凸包面积(答案÷50) 题解 凸包裸题. 代码 #include <cstr ...
- [BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)
[BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yu ...
- poj2186 Popular Cows 题解——S.B.S.
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 29642 Accepted: 11996 De ...
- POJ-3348 Cows 计算几何 求凸包 求多边形面积
题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...
- 洛谷 SP740 TRT - Treats for the Cows 题解
SP740 TRT - Treats for the Cows 题目描述 FJ has purchased N (1 <= N <= 2000) yummy treats for the ...
- 洛谷 P2858 [USACO06FEB]奶牛零食Treats for the Cows 题解
P2858 [USACO06FEB]奶牛零食Treats for the Cows 题目描述 FJ has purchased N (1 <= N <= 2000) yummy treat ...
- 洛谷 P3088 [USACO13NOV]挤奶牛Crowded Cows 题解
P3088 [USACO13NOV]挤奶牛Crowded Cows 题目描述 Farmer John's N cows (1 <= N <= 50,000) are grazing alo ...
随机推荐
- hdu2112HDU Today(floyd+map数组对字符串的应用)
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 180706-BigDecimal除法的精度问题
BigDecimal除法的精度问题 在使用BigDecimal的除法时,遇到一个鬼畜的问题,本以为的精度计算,结果使用返回0,当然最终发现还是自己的使用姿势不对导致的,因此记录一下,避免后面重蹈覆辙 ...
- ntp-redhat 同步时间配置
1. 选作一个机器作为ntp 服务端,例如 ip 为192.168.0.1 1)安装 ntp服务 yum install ntp 2) 修改ntp.conf 文件 vi /etc/ntp.conf 注 ...
- tpo-09 C1 Advice on a term paper's topic
第 1 段 1.Listen to a conversation between a student and her professor. 请听一段一名学生和教授讨论的对话. 第 2 段 1.Befo ...
- python中出现ascii编码问题的解决办法
一劳永逸,一次性全盘解决的办法 环境变量中去设置 以centos 7为例: vim /etc/profile export PYTHONIOENCODING=utf-8 source /etc/pro ...
- fastCMS八大核心对象
fastCMS内置system对象,该对象包含八大核心对象,应用于不同的操作场景,分别是: 1.system.string 对象(处理字符类操作) 2.system.number 对象(处理数字类操作 ...
- Django学习总结①
Django基础环境配置好以后,打开pycharm,创建Django项目 视图views 中需要导入 django.http ---> HttpResponse models库 - 常用方法: ...
- 关于Python3中函数:
# 关于Python3中函数: - 定义 定义函数使用关键字def,后接函数名和放在圆括号()中的可选参数列表,函数内容以冒号起始并且缩进.一般格式如下:``` def 函数名(参数列表): &quo ...
- Windows10系统tensorflow-gpu安装
准备工作 安装前请确保自己的显卡支持gpu加速,支持加速的gpu型号可在下面的链接中查询. https://www.geforce.com/hardware/technology/cuda/suppo ...
- 名人问题 算法解析与Python 实现 O(n) 复杂度 (以Leetcode 277. Find the Celebrity为例)
1. 题目描述 Problem Description Leetcode 277. Find the Celebrity Suppose you are at a party with n peopl ...