hdu 1392 Surround the Trees(凸包模板题)

hdu1392-Surround the Trees 求凸包 Graharm算法解决凸包的模板题 阅读详情


hdu 1392 Surround the Trees


凸包模板直接套,注意n==2的时候只算一半

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 105
struct point
{
    int x,y;
    bool operator < (const point &a) const
    {
        if(a.x==x) return y<a.y;
        else return x<a.x;
    }
};
struct vector
{
    int x,y;
    vector(int x,int y):x(x),y(y){}
};
vector operator - (point a,point b)
{
    return vector(a.x-b.x,a.y-b.y);
}
int cross(vector a,vector b)
{
    return a.x*b.y-a.y*b.x;
}
double getlen(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int convex_hull(point *p,int n,point *ch)
{
    sort(p,p+n);
    int m=0;
    for(int i=0;i<n;i++)
    {
        while(m>1&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<0) m--;
        ch[m++]=p[i];
    }
    int k=m;
    for(int i=n-2;i>=0;i--)
    {
        while(m>k&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<0) m--;
        ch[m++]=p[i];
    }
    if(n>1) m--;
    return m;
}
int main()
{
    point p[MAXN],ch[MAXN];
    int n;
    while(scanf("%d",&n)!=EOF&&n)
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&p[i].x,&p[i].y);
        int m=convex_hull(p, n, ch);
        double ans=0;
        for(int i=0;i<m;i++)
            ans+=getlen(ch[i], ch[(i+1)%m]);
        if(n==2) ans/=2.0;
        printf("%.2lf\n",ans);
    }
    return 0;
}


安装IC Complier 2(安装synposys的其他工具也可以来看看,因为殊途同归) 安装ICC2 阅读详情

相关推荐

Simeck算法流程

算法流程 paper在此:https://eprint.iacr.org/2015/612.pdf x ⋘\lll⋘ c denotes the cyclic shift of x to the left by c bits. x & y is the bitwise AND of x and y. x⊕yx \oplus yx⊕y is the exclusive-or (XOR) of x and y. github代码在此:https://github.com/bozhu/Simeck

Simp123 1079

凸包(讲解+模板+例题)

凸包讲解 例题POJ 2187 模板 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> using namespace std; struct node { int x,y; }; node...

September_的博客 1070

智能驾驶感知模块的测试评估方法(上)

对于智能驾驶系统而言,感知模块是开发难度最大、投入资源最多的核心部分。在智能驾驶开发团队内部,感知模块需要独立进行评测才能及早发现潜在缺陷或判断性能是否有改进。随着近几年BEV、OCC、E2E等新技术方案被越来越多企业应用,感知的评测变得越来越艰难,效率也变得越来越低下。本文作者基于在智驾测试行业多年经验,试图总结感知评测的基本规律和效率提升方法,以供读者一些启发。

vincent_321的博客 2565

凸包问题(模板)

Andrew算法模板:具体实现: 1.把所有点按照x从小到大进行排序 (x同则y用y进行排序) 2.删除重复序列后得到序列p1,p2.。。, 3.让后把p1 p2放入凸包中 从p3开始。当新点在凸包“前进”方向的左边时继续,否则依此删除最近加入凸包的点 直到新点在左边 这个算法你可以理解为逆时针画圆 每次半个圆int Cross(point A,point B)//叉积 {

cpfor 382

部署资源管理系统chemx

资源管理系统的部署教程

weixin_40784215的博客 826

IMA知识库:从0到1的架构设计与实践

本文探讨了AI时代知识库系统的架构设计与演进路径。通过分析知识入库、知识管理和知识应用三大核心业务流程,提出了应对数据多样性、处理标准化、流量洪峰等挑战的解决方案。重点介绍了基于统一数据格式的解耦设计、异步处理架构、服务拆分策略以及权限安全体系,构建了一个稳定、高效且可扩展的知识库系统。文章强调优秀架构需要持续演进,通过识别薄弱点不断优化,最终实现技术方案与业务需求的平衡。

lovehu6686的博客 1744

1214:凸包模板(Andrew算法)

1214: [视频]【计算几何】凸包 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 55 [提交][状态][讨论版] 题目描述 【题意】 在一个平面坐标系上有n个点,用笔画一个多边形,使得多边形包含这n个点(点在多边形的边上也算包含)。 求多边形的最小周长。 【输入格式】 第一行整数 n (1 <= n <= 1000),表示有n个点。 下来n行,每

hg_zhh 490

5GCPE与4G物联网卡兼容实战:通过AT指令修改IMEI实现设备迁移

本文详细介绍了如何通过AT指令修改5GCPE设备的IMEI,实现4G物联网卡的设备迁移。从硬件准备、驱动安装到串口工具配置,再到具体的AT指令操作步骤,提供了全面的实战指南。文章还包含信号优化、APN设置等实用技巧,帮助用户顺利完成设备迁移并提升网络性能。

weixin_28684757的博客 649

[POJ3348]Cows 凸包模板题

CowsTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 10262 Accepted: 4510DescriptionYour friend to the south is interested in building fences and turning plowshares into swords. In order to h...

LvYanchang的博客 538

交通流预测爬坑记(一):交通流数据集,原始数据

常用的交通流数据集,持续更新~~

K_first的博客 4万+

英飞凌 AURIX TC3XX 系列单片机的 NVM-Flash 介绍

简单介绍英飞凌 AURIX TC3XX 系列多核单片机的 Flash,便于快速上手使用

大橙子的博客 6647

凸包模板题

POJ 1113 这道题是凸包第一题,也是我学习算法的一题。直接看了题解,看别人怎么写的然后自己模仿,写出自己的凸包模板 这道题,直接凸包然后算个长度就可以了 #include #include #include #include #include using namespace std; struct point { int x,y,dx,dy; point():x(0)

小菜鸟。。 730

[ATF]-smc指令详解

1、在ree/tee调用smc之前 2、调用smc之后,cpu触发同步异常,进入ATF的sync_exception_aarch64—>handle_sync_exception—>smc_handler64处理函数 在smc_handler64中又调用了smc_handler func smc_handler64 /* ---------------------------------------------- * Detect if this is a RUN_IMAGE or ot

baron-周贺贺-代码改变世界ctw 1万+

hdu 1392 Surround the Trees 凸包模板题

#include #include #include #include #include using namespace std; const int maxn=111; struct node{ int x,y; }e[maxn],res[maxn]; int cmp(node a,node b) { if(a.x==b.x)return a.y<b.y; re

冷月之殇 812

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

HDU 1392 Surround the Trees(凸包模板题)

  Surround the Trees   Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12658 Accepted Submission(s): 4904     Problem Description There are...

ii0789789789的博客 313

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

hdu-1392-Surround the Trees_凸包Graham算法模板题

Surround the TreesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12525    Accepted Submission(s): 4851Problem DescriptionThere are a lot of tre...

qq_36914923的博客 218

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

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

HDU1392 Surround the Trees(凸包模版题)

给你一个数n,代表一共有多少课树,然后给你n对点表示每棵树的坐标,要你求一个多边形能把所有的点包起来。

不积跬步无以至千里 607

hdu_1392 Surround the Trees(凸包)

http://acm.hdu.edu.cn/showproblem.php?pid=1392 分析: 用了凸包模板很快就可以

naturelan的专栏 804

HDU 1392 Surround the Trees (凸包周长)

题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope...

G19850917的博客 197

HDU1392 Surround the Trees

本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! 题目链接:HDU1392 正解:凸包 解题报告:   凸包模板题。 //It is made by...

dgoh41514的博客 143

HDU1392:Surround the Trees(凸包问题)

Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7164    Accepted Submission(s): 2738 Problem Description There a

TOKHE的专栏 1507

HDU 1392 Surround the Trees (凸包)

HDU 1392 Surround the Trees (凸包) 题意 给定二维平面nnn个点坐标,求凸包周长。 思路 GrahamGrahamGraham 扫描法,有时间具体写。 代码先贴上 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7; #define mst(a,b) memset(a,b,size

Harris-H的博客 507

ACM-计算几何之Surround the Trees——hdu1392

ACM 计算几何 Surround the Trees hdu1392 凸包周长

继续激情,继续奋斗。 1900

hdu 1392 Surround the Trees 凸包周长

Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9486    Accepted Submission(s): 3648 Problem Description There a

EventQueue的博客 637

HDU 1392 Surround the Trees【凸包】

1.题目 题目链接:点这儿! 2.解决方法 在一个二维平面上给出一个点集P,用一根橡皮筋将这些点捆住,形成的也就是一个由P组成的最小多边形,这个凸多边形被称作凸包;求凸包的周长,常见的有Graham扫描法、Andrew算法;后者是前者的改进,本题使用Andrew算法。 Andrew算法:将所有点按照x升序排序,若是x相等,则以y进行升序排序。从最左下方的点开始,求下凸壳;再从最右上方开始,求上凸壳。上下凸壳长度之和即为凸包周长。求凸壳的每一步,尽量将栈最上方两点构成的向量“逆时针旋转”。 3.代码 #inc

kingdom365的博客 220

HDU 1392 Surround the Trees【凸包 | 模板】

题目链接 题目描述: 凸包模板题 凸包: 凸包 (Convex hull) 问题: 给定一些点,求能把所有这些点包含在内的面积最小的多边形。可以想象有一个很大的橡皮箍,它把所有的点都箍在里面,在橡皮箍收紧之后,绕着最外围的点形成的多边形就是凸包。 求凸包的算法 (Andrew算法): 算法做两次扫描,先从最左边的点沿“下凸包”扫描到最右边,再从最右边的点沿“上凸包”扫描到最左边,“上凸包”和“下凸包”合起来就是完整的凸包。 步骤: 把所有点按照横坐标 x 从小到大进行排序,如果 x 相同,按 y 从小到

weixin_44258590的博客 232
上一篇: hdu 2108 Shape of HDU(计算几何)
下一篇: hdu 1115 Lifting the Stone(求n边形的重心)
yjCola
博客等级 码龄14年 4粉丝 138原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值