题目大意:求凸包面积。

解题关键:模板题,叉积求面积。

这里的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的更多相关文章

  1. poj3348 Cows 凸包+多边形面积 水题

    /* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...

  2. POJ3348 Cows 计算几何 凸包

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ3348 题意概括 求凸包面积(答案÷50) 题解 凸包裸题. 代码 #include <cstr ...

  3. POJ-3348 Cows 计算几何 求凸包 求多边形面积

    题目链接:https://cn.vjudge.net/problem/POJ-3348 题意 啊模版题啊 求凸包的面积,除50即可 思路 求凸包的面积,除50即可 提交过程 AC 代码 #includ ...

  4. poj3348 Cows 凸包 叉积求多边形面积

    graham扫描法,参考yyb #include <algorithm> #include <iostream> #include <cstdio> #includ ...

  5. 【kuangbin专题】计算几何_凸包

    1.poj1113 Wall 题目:http://poj.org/problem?id=1113 题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r.求这条线的最小距离是多少? 分析 ...

  6. 【poj3348】 Cows

    http://poj.org/problem?id=3348 (题目链接) 题意 给出平面上n个点,以这n个点中的一些围成的多边形面积 div 50的最大值. Solution 凸包求面积. 很好做, ...

  7. POJ3348:Cows——题解

    http://poj.org/problem?id=3348 题目大意:用已给出的点围出面积最大的凸包,输出面积/50(向下取整) —————————————————————————— 第一道凸包?以 ...

  8. [LeetCode] Bulls and Cows 公母牛游戏

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  9. POJ 2186 Popular Cows(Targin缩点)

    传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 1292 ...

随机推荐

  1. SOLID

    S.O.L.I.D是面向对象设计和编程(OOD&OOP)中几个重要编码原则(Programming Priciple)的首字母缩写. SRP The Single Responsibility ...

  2. mysql 关联关系

    一 单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 二 关键 ...

  3. mysql_异常_01_Access denied for user 'root'@'192.168.1.13' (using password: YES)

    一.异常现象 使用navicat premuim 连接 虚拟机mysql数据库时 ,抛出如下错误: Access denied for user 'root'@'192.168.1.13' (usin ...

  4. 树莓派相机操作 —— luvcview 的安装、raspistill:摄像头命令

    MMAL (Multimedia Abstraction Layer) RaspiCam Documentation 0. lucview 的安装 安装命令:sudo apt-get install ...

  5. 畅通工程再续 (kruskal算法的延续)

    个人心得:这题其实跟上一题没什么区别,自己想办法把坐标啥的都给转换为对应的图形模样就好了 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实 ...

  6. django的settings文件

    转载:http://www.cnblogs.com/likeshan168/articles/3596344.html

  7. 浅谈K-D Tree

    初步认识\(K-D\) \(Tree\) \(K-D\) \(Tree\)是一种基于空间分割的二叉树形数据结构,一般用于高维信息检索.因为\(OI\)中很多问题都能转化为高维信息检索,所以\(K-D\ ...

  8. POJ3321(dfs序列+树状数组)

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25711   Accepted: 7624 Descr ...

  9. WCF svcutil工具

    通过SvcUtil.exe生成客户端代码和配置 WCF服务调用通过两种常用的方式:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式,一种是通过ChannelFactory直接创建服务 ...

  10. Swing编程中为什么对Panel设置了位置后,它的lable位置也跟这变了呢?

    总结: package com.da; //这里我不明白,我对每一个Panle里的按钮设置了位置BorderLayout.SOUTH.可是为什么Lable的位置和它一样同步设置了呢? //做一个界面 ...