POJ - 3348Cows ————计算几何(凸包计算)

1015 - 计算几何之Graham扫描法求凸包 - Cows(POJ 3348) 传送门   题意 给你一堆点,求这些点的凸包,并求出面积   分析 很久之前就做过的一道题了,还记得那是凯爷(凯爷好厉害好厉害的)讲的,是Jarris步进法:按照横纵坐标对所有的点进行排序(横坐标优先) 然后就是和Graham类似的方法了,边扫描边弹出栈,只是Jarris算法要进行两遍扫描,一遍解决了下面一半的凸包,一遍解决上面一半的凸包,拼在一起就是一个完整的凸包咯 但这不是今天... 阅读详情

Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.

However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.

Input
The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).

Output
You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.

Sample Input
4
0 0
0 101
75 0
75 101
Sample Output
151


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int MAXN=1e4+5,inf=0x3f3f3f;
struct Pt{
    double x,y;
    Pt(){}
    Pt(double _x,double _y)
    {
        x=_x;
        y=_y;
    }
}p[MAXN],s[MAXN];
int n;
double  dir(Pt p1,Pt p2,Pt p3)
{
    return (p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y);
 } 
double dis(Pt p1,Pt p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)-(p1.y-p2.y)*(p1.y-p2.y));
}
bool cmp(Pt p1,Pt p2)
{
    double te=dir(p[0],p1,p2);
    if(te<0)    return 1;
    else if(te==0 && dis(p[0],p1)<dis(p[0],p2)) return 1;
    return 0;
}

double solve()
{
    int pos;
    double minx,miny;
    minx=miny=inf;
    for(int i=0;i<n;i++)
    {
        if(p[i].x<minx||(p[i].x==minx)&&p[i].y<miny)
        {
            minx=p[i].x;
            miny=p[i].y;
            pos=i;
        }
    }
    swap(p[0],p[pos]);
    sort(p+1,p+n,cmp);
    int top=2;
    p[n]=p[0];
    s[0]=p[0];s[1]=p[1];s[2]=p[2];
    for(int i=3;i<=n;i++)
    {
        while(top>=2 && dir(s[top-1],s[top],p[i])>=0)   top--;
        s[++top]=p[i];
    }
    double ans=0;
    for(int i=1;i<top-1;i++)
        ans-=dir(s[0],s[i],s[i+1]);
    return ans/2;
}
int main()
{
    ios::sync_with_stdio(0);
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            cin>>p[i].x>>p[i].y;
        cout<<(int)solve()/50<<endl;    
    }
    return 0;
}





凸包面积的计算~~~~ stack<point> s; cin>>n; for(i = 0; i < n; i++) cin>>pot[i].x>>pot[i].y; x = pot[0].x; y = pot[0].y; p = 0; for(i = 1; i < n; i++) //寻找最左上的点 { if(pot[i].y < y || (pot[i].y == y && pot[i].x < x)) { x = pot[i].x; y = pot[i].y; p = i; } } p0.x = x; p0.y = y; swap(pot[0], pot[p]); sort(pot + 1, pot + n, cmp); //排序 s.push(p0); s.push(pot[1]); s.push(pot[2]); point t; for(i = 3; i < n; i++) //凸包 { while(!s.empty()) { t = s.top(); s.pop(); p = ( pot[i].x-s.top().x)*(t.y-s.top().y) - (t.x-s.top().x)*(pot[i].y-s.top().y ); if(p < 0) { s.push(t); break; } } s.push(pot[i]); } double area = 0; t = s.top(); s.pop(); area += (p0.x * t.y - p0.y * t.x)/2.0; while(!s.empty()) { area += (t.x * s.top().y - t.y * s.top().x)/2.0; t = s.top(); s.pop(); } if(area < 0) area = -area; cout<<fixed<<setprecision(3)<<area<<endl; 立即下载

相关推荐

Verilog实现SPI通信协议驱动设计

线性序列机实现SPI协议

H19981118的博客 6086

凸包问题(含叉积讲解)

凸包预备知识叉积1.概念的引入2.定义3.应用(1)求解三角形(平行四边形)面积(2)点定位(3)极角排序1.用叉积计算极角(精度高,时间慢)2.atan2函数(时间快,精度较差)凸包1.定义2.求解方法Graham's Scan法总结 预备知识 叉积 1.概念的引入 在平面中我们为了度量一条直线的倾斜状态,为引入倾斜角这个概念。而通过在直角坐标系中建立tan α = k,我们实现了将几何关系和代数关系的衔接,这其实也是用计算机解决几何问题的一个核心,计算机做的是数值运算,因此你需要做的就是把几何关系用代数

Royen_的博客 2545

Ubutntu下使用realsense d435i(二):获取某二维像素点的三维坐标

00 准备工作 准备工作包括安装驱动以及pyrealsense2,具体可参考上一篇: Ubutntu下使用realsense d435i(一):准备工作以及安装pyrealsense2 https://blog.youkuaiyun.com/gyxx1998/article/details/121461293 01 通过二维像素点获得物体三维坐标 这个在上一篇已经介绍了代码: realsense d435i获取某像素点三维坐标(计算深度和点云两种方法) https://blog.youkuaiyun.com/gyxx1998/

gyxx1998的博客 9945

(转载)凸包问题的五种解法

前言: 首先,什么是凸包? 假设平面上有p0~p12共13个点,过某些点作一个多边形,使这个多边形能把所有点都“包”起来。当这个多边形是凸多边形的时候,我们就叫它“凸包”。如下图: 然后,什么是凸包问题? 我们把这些点放在二维坐标系里面,那么每个点都能用 (x,y) 来表示。 现给出点的数目13,和各个点的坐标。求构成凸包的点? 解一:穷举法(蛮力法) 时间复杂度:O(n³)。 思路:两点确定一条直线,如果剩余的其它点都在这条直线的同一侧,则这两个点是凸包上的点,否则就不是。 步骤...

门前大桥下,游过一群鸭,快来看一看,原来是C++ 3548

避开STM32中断优先级配置的坑:HAL_NVIC_SetPriority()参数你真的用对了吗?

本文深入解析STM32中断优先级配置中的关键问题,重点剖析HAL_NVIC_SetPriority()函数的正确使用方法。通过实际案例揭示优先级分组设置、抢占优先级与子优先级的区别,提供多中断系统中的优化策略和调试技巧,帮助开发者避免常见配置错误,提升系统稳定性。

weixin_42532938的博客 424

芯片散热技术突破:多尺度结构与VC集成方案解析

在半导体技术快速发展的背景下,芯片散热成为制约性能提升的关键瓶颈。传统散热技术如风冷和水冷已接近物理极限,而两相浸没式液冷技术凭借其超高传热系数成为新的解决方案。通过多尺度表面结构设计与真空腔均热板(Vapor Chamber)的集成创新,可以显著提升沸腾性能,降低沸腾起始温差(ONB)并突破临界热流密度(CHF)限制。这种技术在数据中心、高性能计算(HPC)和边缘计算等高热流密度场景中具有重要应用价值,能有效提升能效比(PUE)并降低能耗。

weixin_36288992的博客 155

Cows (能容纳多少头牛)

POJ - 3348  Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on b...

qq_42759455的博客 263

Hadoop在大数据领域的电商数据分析案例

随着电商行业的迅猛发展,每天都会产生海量的数据,如用户浏览记录、购买行为、商品信息等。如何从这些数据中提取有价值的信息,为电商企业的决策提供支持,成为了电商企业面临的重要问题。Hadoop作为一个开源的分布式计算平台,具有高可靠性、高扩展性和高效性等特点,能够很好地处理大数据。本文的目的就是通过实际案例,详细介绍Hadoop在电商数据分析中的应用,范围涵盖了从数据采集、存储到分析的整个流程。本文首先介绍背景信息,让读者了解Hadoop在电商数据分析中的重要性和应用场景。

Java大师兄的博客 1179

2022 CCPC 威海 C(计算几何)

一句话题解就是当且仅当存在5个点不共线。即使4点共线,也只要找到剩下那个不共线的,就可以把他作为A。只要固定前4个点,然后O(n)遍历剩余的点,如果存在一个点和前4个点不共线,说明有解。暴力枚举哪个点作为中心点,即可求解。给定n个点,找5个点。使得中心点A,与其余四个点B、C、D、E组成的线段AB、AC、AD、AE的交点只有点A。

xianqiuyigedao的博客 469

SAP RAP 里的 EML 全解:从语言定位到事务语义,再到真实案例的落地方式

摘要:EML(Entity Manipulation Language)是ABAP RAP模型的核心组件,作为ABAP的子集用于操作业务对象(BO)。它通过声明式语法(READ/MODIFY/EXECUTE/COMMIT)统一访问BO的行为与数据,并由RAP运行时自动处理校验、锁定、草稿管理等生命周期。EML将业务语义融入代码,确保与Fiori应用共享同一套校验逻辑,并通过FAILED/REPORTED/MAPPED管道传递错误与消息。其事务控制(IN LOCAL MODE与COMMIT ENTITIES)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 528

凸包模板 / Andrew算法 poj3348

凸包是计算几何中相对基础的内容,主流解法为Graham扫描法和Andrew算法

m0_54646258的博客 383

PyTorch深度学习实战(6)——神经网络性能优化技术

神经网络性能优化技术是指通过改进神经网络的结构、参数初始化、正则化和训练过程等方面来提高其性能和泛化能力的方法。优化技术的选择和调试需要根据具体问题进行,通过不断实验和调整,找到最适合网络的优化策略。本节首先训练了一个简单的全连接网络,然后在此基础上介绍了简单有效的神经网络性能提升技巧。

盼小辉丶的博客 1万+

POJ3348-Cows【凸包,计算几何】

正题 题目大意 凸包的面积S,求⌊S/50⌋\lfloor S/50\rfloor⌊S/50⌋ 解题思路 求凸包,然后求面积,然后求答案。 codecodecode #include&amp;lt;cstdio&amp;gt; #include&amp;lt;algorithm&amp;gt; #include&amp;lt;cmath&amp;gt; #define N 10010 using namespace std;

QuantAsk 379

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

【计算几何 凸包】POJ_3348 Cows

题意 求出凸包的面积/50。 思路 用grahamgrahamgraham算法算出凸包的点,然后再用叉积算出多边形的面积就好了。 代码 #include&lt;cmath&gt; #include&lt;cstdio&gt; #include&lt;algorithm&gt; struct P{ double x, y, q; }p[10001]; int s[10001], top; i...

GOODPLACE 216

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

POJ3348 Cows 计算几何 凸包

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

weixin_30341745的博客 144

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

poj3348——Cows【凸包,计算几何】

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10652   Accepted: 4665 Description Your friend to the south is interested in building fe...

xiang_hehe的博客 291

【计算几何/凸包】POJ 3348 Cows

Cows Time Limit: 2000MS Memory Limit: 65536K Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas advent...

落花水面 756

POJ 3348 Cows【计算几何】【单调栈】【凸包Graham算法】

凸包

JA_yichao欢迎你 cnblogs账号:https://www.cnblogs.com/mayichao/ 195

[笔记] 计算几何-凸包 POJ-3348 Cows

题目:http://poj.org/problem?id=3348 求凸包面积 算法:先对点的横坐标排序,从左到右先计算下凸边,再从右到左计算上凸边.复杂度比Graham Scan法稍稍要高(两次遍历点集),但实现较容易 #include <stdio.h> #include <algorithm> using namespace std; struct...

weixin_30273501的博客 103

poj 3348:Cows(计算几何,求凸包面积)

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6199   Accepted: 2822 Description Your friend to the south is interested in building fences and turning ...

weixin_33767813的博客 231

poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

Cows Time Limit:2000MS Memory Limit:65536K Total Submissions:7038 Accepted:3242 Description Your friend to the south is interested in building fences and turning ...

weixin_30268071的博客 138

凸包水题

poj3348Cows http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=10278 Cows Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Statu

hahaAll的博客 348

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

/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include&lt;stdio.h&gt; #include&lt;math.h&gt; #include &lt;algorithm&gt; using namespace std; const double eps = 1e-8; struct point { ...

weixin_34357267的博客 103

ACM-计算几何之Cows——poj3348

ACM 计算几何 Cows poj3348 凸包面积

继续激情,继续奋斗。 1885
上一篇: POJ - 1113 Wall ————计算几何
下一篇: POJ - 1265 Area ————计算几何(皮克定理)
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值