[poj3348]Cows
题目大意:求凸包面积。
解题关键:模板题,叉积求面积。
这里的cmp函数需要调试一下,虽然也对,与普通的思考方式不同。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
struct point{
double x,y;
point(){}
point(double _x,double _y){x=_x;y=_y;}
point operator-(const point &b)const{return point(x-b.x,y-b.y);}
double operator^(const point &b)const{return x*b.y-y*b.x;}
double operator*(const point &b)const{return x*b.x+y*b.y;}
}A[],result[];
int dist(point a,point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int cp(point p1,point p2,point p3){
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
bool cmp(point a,point b){
int ans=cp(A[],a,b);
if(ans==) return dist(A[],a)-dist(A[],b)<=;
else return ans>;
}
int n;
int main(){
while(scanf("%d",&n)!=EOF){
int pos=;
for(int i=;i<n;++i){
scanf("%lf%lf",&A[i].x,&A[i].y);
if(A[pos].y>=A[i].y){
if(A[pos].y==A[i].y){
if(A[pos].x>A[i].x)pos=i;
}
else pos=i;
}
}
if(n<){
printf("0\n");
continue;
}
int top=;
swap(A[],A[pos]);
sort(A+,A+n,cmp);
result[]=A[];result[]=A[];
for(int i=;i<n;++i){
while(cp(result[top-],result[top],A[i])<)top--;
result[++top]=A[i];
} double s=;
for(int i=;i<top;++i){
point t1=result[i]-result[],t2=result[i+]-result[];
double area=fabs(t1^t2)*0.5;
s+=area;
}
printf("%d\n",(int)(s/50.0));
}
return ;
}
[poj3348]Cows的更多相关文章
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...
- POJ3348 Cows 计算几何 凸包
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ3348 题意概括 求凸包面积(答案÷50) 题解 凸包裸题. 代码 #include <cstr ...
- POJ-3348 Cows 计算几何 求凸包 求多边形面积
题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...
- poj3348 Cows 凸包 叉积求多边形面积
graham扫描法,参考yyb #include <algorithm> #include <iostream> #include <cstdio> #includ ...
- 【kuangbin专题】计算几何_凸包
1.poj1113 Wall 题目:http://poj.org/problem?id=1113 题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r.求这条线的最小距离是多少? 分析 ...
- 【poj3348】 Cows
http://poj.org/problem?id=3348 (题目链接) 题意 给出平面上n个点,以这n个点中的一些围成的多边形面积 div 50的最大值. Solution 凸包求面积. 很好做, ...
- POJ3348:Cows——题解
http://poj.org/problem?id=3348 题目大意:用已给出的点围出面积最大的凸包,输出面积/50(向下取整) —————————————————————————— 第一道凸包?以 ...
- [LeetCode] Bulls and Cows 公母牛游戏
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
随机推荐
- css3——transition属性和opacity属性
[transition-duration] 是一个css3属性,规定完成过度效果需要花费的时间(一秒或毫秒计).语法:transition-duration: time;time : 规定完成过 ...
- Mac开机启动
1. Finder打开资源库的LaunchAgents目录. 打开Finder,按⇧⌘G,输入 /Library/LaunchAgents/ 以及 ~/Library/LaunchAgents/ 2. ...
- Shiro安全配置
主要还是整合了本地ehcache,集群session管理过段时间放出 <?xml version="1.0" encoding="UTF-8"?> ...
- IDEA Tomcat服务器 更新.jsp时,页面刷新无法同步修改
这是因为在配置服务时没有配置好: on frame deactivation部分
- WC2019 滚粗记
离开的时候一定是笑着离开的 不然就再也回不来了 广州二中,七月再见
- (转载)Windows: "net use" command introduction
1)建立空连接: net use ""IP"ipc$ "" /user:"" (一定要注意:这一行命令中包含了3个空格) 2)建立 ...
- 5、Selenium+Python自动登录163邮箱发送邮件
1.Selenium实现自动化,需要定位元素,以下查看163邮箱的登录元素 (1)登录(定位到登录框,登录框是一个iframe,如果没有定位到iframe,是无法定位到账号框与密码框) 定位到邮箱框( ...
- CEF源码编译
CEF的构造说明:https://bitbucket.org/chromiumembedded/cef/wiki/BranchesAndBuilding chromium的源码地址:https://c ...
- UIButton 不同状态图片来回切换
做百度地图是否显示路况信息,用到两种状态的图片 第一种方法:用Bool进行标记 声明一个 Bool _isRoad; - (void)roadBtnAction:(UIButton *)sender ...
- Elasticsearch的过滤查询
声明:我使用的elasticsearch的版本是5.4.0,具体参考下面的链接 https://www.elastic.co/guide/en/elasticsearch/reference/5.4/ ...