题目大意:求凸包面积。

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

这里的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. Java 反射机制应用实践

    反射基础 p.s: 本文需要读者对反射机制的API有一定程度的了解,如果之前没有接触过的话,建议先看一下官方文档的Quick Start(https://docs.oracle.com/javase/ ...

  2. ural 2022 Riding a Toad

    2022. Riding a Toad Time limit: 1.0 secondMemory limit: 64 MB A tribe of leafmen live in the old for ...

  3. Android自定义组件之ListView

    1-ListView简介 在android开发中ListView是比较常用的组件,它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示.一个ListView通常有两个职责. (1)将数据填充到 ...

  4. AI探索(三)Tensorflow编程模型

    Tensorflow编程模型 ....后续完善 import os os.environ[' import numpy as np num_points = data_array = [] for i ...

  5. 《Effective C++》——条款04:确定对象使用前已先被初始化

    读取未初始化的值会导致不明确的行为.在某些平台上,仅仅只是读取未初始化的值,就可能让你的程序终止运行.更可能的情况是读入一些“半随机”bits,污染了正在进行读取动作的那个对象,最终导致不可预知的程序 ...

  6. 201621123014《Java程序设计》第十周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1. 常用异常 结合题集题目7-1回答 1.1 自己以前编写的代码中经常出现 ...

  7. hdoj-1715-大菲波数(大斐波那契数列)

    题目链接 import java.util.*; import java.math.*; public class Main{ public static void main(String[] arg ...

  8. CodeForces - 651D:Image Preview (双指针&)

    Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed ...

  9. Java中print()、printf()、println()的区别?

    区别: 1.printf主要是继承了C语言的printf的一些特性,可以进行格式化输出 2.print就是一般的标准输出,输入信息后不会换行 3.println输入信息会换行 参照JAVA API的定 ...

  10. 洛谷 P3048 [USACO12FEB]牛的IDCow IDs

    题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, ...