[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 ...
随机推荐
- 导入工程“The import android cannot be resolved”错误
project - Properties - android 1.Project Build Target 勾选响应的SDK 2.default.properties文件,把target = andr ...
- 代码题(59)— 字符串相加、字符串相乘、打印最大n位数
1.415. 字符串相加 给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和. 思路:和链表相加类似,求进位. class Solution { public: string addS ...
- python如何获取多个excel单元格的值
一. 获取多个单元格的值报错:AttributeError: 'tuple' object has no attribute 'value' 需要读取的sample.xlsx 代码读取的是A3:B10 ...
- poj 2395 bfs/记录路径
http://poj.org/problem?id=2935 Basic Wall Maze Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- C#中的线程(四)高级话题
C#中的线程(四)高级话题 Keywords:C# 线程Source:http://www.albahari.com/threading/Author: Joe AlbahariTranslato ...
- 分布式_理论_05_ 一致性算法 Paxos
一.前言 二.参考资料 1.分布式理论(五)—— 一致性算法 Paxos 2.分布式理论(五) - 一致性算法Paxos
- SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)
一.spring cloud简介 spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选.分布式会话等等.它运 ...
- Debian For ARM mysql-server install information
/**************************************************************************** * Debian For ARM mysql ...
- svn 服务器安装包下载地址
svn 服务器安装包下载地址 https://www.visualsvn.com/server/download/
- 在Windows 7上安装ACE 6.1.0
主机环境 操作系统:Windows 7 专业版准备ACE 用浏览器打开http://download.dre.vanderbilt.edu/,下载ACE-6.1.0和ACE-html-6. ...