POJ - 1113 Wall ————计算几何

学习凸包(三):凸包练习 POJ 1113 NULL 博文链接:https://128kj.iteye.com/blog/1748635 立即下载

nce upon a time there was a greedy King who ordered his chief Architect to build a wall around the King’s castle. The King was so greedy, that he would not listen to his Architect’s proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.
这里写图片描述

Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King’s requirements.

The task is somewhat simplified by the fact, that the King’s castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle’s vertices in feet.
Input
The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King’s castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle.

Next N lines describe coordinates of castle’s vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
Output
Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King’s requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.
Sample Input
9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200
Sample Output
1628
Hint
结果四舍五入就可以了


还是白书上的模板比较好用呢

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
const double PI=acos(-1.0);
const double EPS=1e-10;
double add(double a,double b)
{
    if(abs(a+b)<EPS*(abs(a)+abs(b)))
        return 0;
    return a+b;
}
struct Point
{
    double x,y;
    Point () {}
    Point(double x,double y) : x(x),y(y){
    }
    Point operator + (Point p) {
        return Point(add(x,p.x),add(y,p.y));
    }
        Point operator - (Point p) {
        return Point(add(x,-p.x),add(y,-p.y));
    }
        Point operator * (double d) {
        return Point(x*d,y*d);
    }
    double dot(Point p)
    {
        return add(x*p.x,y*p.y);
    }
    double det(Point p){
        return add(x*p.y,-y*p.x);
    }
};

bool cmp_x(const Point& p,const Point& q)
{
    if(p.x!=q.x)
    return p.x<q.x;
    return p.y<q.y;
}
vector<Point> tu(Point* ps,int n)
{
    sort(ps,ps+n,cmp_x);
    int k=0;
    vector <Point>qs(n*2);
    for(int i=0;i<n;i++)
    {
        while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<0)
        k--;
        qs[k++]=ps[i];
    }
    for(int i=n-2,t=k;i>=0;i--)
    {
        while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
        k--;
        qs[k++]=ps[i];

    }
    qs.resize(k-1);
        return qs;
}
double dis(Point p1,Point p2)
{
    return sqrt(fabs((p1.x-p2.x)*(p1.x-p2.x)-(p1.y-p2.y)*(p1.y-p2.y)));
}
Point ps[10006];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%lf %lf",&ps[i].x,&ps[i].y);
    vector <Point> qs=tu(ps,n);
    double ans=0;
    for (int i=0;i<qs.size(); i++)
        ans+=sqrt(fabs(qs[i+1].x-qs[i].x)*fabs(qs[i+1].x-qs[i].x)+fabs(qs[i+1].y-qs[i].y)*fabs(qs[i+1].y-qs[i].y));

//      ans+=dis(qs[i],qs[i+1]);//为什么?自己写的函数不行?精度不够? 
    ans+=2*PI*m;
    printf("%.0lf\n",ans);
    return 0;
}

POJ1113-Wall【凸包】 北大POJ1113-Wall【凸包】 解题报告+AC代码 立即下载

相关推荐

龙迅LT9611UXC芯片简介:Dual-Port MIPI DSI/CSI to HDMI2.0 with Audio

龙迅半导体推出的LT9611UXC是一款高性能MIPI转HDMI2.0转换器,支持DSI/CSI接口转换,兼容多种视频格式(RGB/YCbCr),最高支持4K@60Hz输出。该芯片集成音频处理(I2S/SPDIF)、色彩空间转换和3D功能,适用于机顶盒、电视盒子等消费电子及车载设备。提供工业级(-40℃~+85℃)和车规级(AEC-Q100认证)版本,采用QFN64封装。

MB16698594834的博客 1334

poj1113(凸包 卷包裹法)

#include #include #include #include using namespace std; struct Point{ int x,y; }s[1005]; bool cmp(Point a,Point b) //选择最下左的点作为起点 { if(a.y==b.y) return a.x<b.x; else return a.y<b.y; } int cross(

zizahn的博客 451

【SABRE 3D, SABRE 3DxT,LAM设备】2025年9月14日-Clamshell 拆卸与安装

Clamshell 拆卸与安装。

weixin_46735260的博客 1691

Wall——凸包模板问题

Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King’s castle. The King was so greedy, that he would not listen to his Architect’s proposals to build a beautiful brick wall with a perfect shape and nice t

five_east_west的博客 287

educoder数字逻辑实训:寄存器设计与应用(Logisim)

第1关:基本寄存器的设计 任务描述 本关任务:在Logisim中,构建由4个D触发器构成的4位基本寄存器,要求上升沿触发,具有异步复位功能。 第2关:移位寄存器的设计 任务描述 本关任务:在Logisim中,构建由4个D触发器构成的4位右移移位寄存器,要求上升沿触发,具有异步复位功能。 第3关:循环移位寄存器的设计 任务描述 本关任务:在Logisim中,构建由4个D触发器构成的4位循环右移移位寄存器,要求上升沿触发,具有异步复位功能以及并行数据同步加载功能。 第4关:并行..

qq_52209002的博客 1万+

本地AI助手部署指南:DeepSeek Harness与Ollama集成实践

AI Agent作为当前人工智能领域的热门技术,通过模拟人类决策过程,能够自主规划、调用工具并执行复杂任务。其核心原理在于将大语言模型的推理能力与外部工具API相结合,形成可闭环的工作流。这种技术架构的价值在于显著提升了AI系统的实用性和自动化水平,使其从单纯的对话工具转变为能够解决实际问题的智能助手。在应用场景上,AI Agent广泛应用于代码生成、数据分析、自动化办公等领域。本文聚焦于如何通过DeepSeek Harness平台与Ollama本地模型的集成,实现隐私安全、离线可用的AI助手部署方案,特别

dengjuanshou7445的博客 476

POJ1113(凸包模板题)

POJ1113 这道题只要求出多边形凸包的周长再加上L为半径的圆的周长即可 下面AC代码: 用分治法有一个不好地方就是最后输出的凸包顶点数组,凸包顶点的顺序既不是顺时针也不是逆时针,所以对于后续的求周长,还要重新让凸包顶点的顺序变成顺时针或者逆时针,如果后面我学到其他的凸包算法再回来补这道题。 #include<vector> #include<math.h> #include<algorithm> #include<iostream> #include

weixin_45699092的博客 362

在 SAP 中启用应收/应付“代扣税(Withholding Tax)”功能,本质上是激活并配置“扩展代扣税(Extended Withholding Tax)”模型

摘要:SAP中启用应收/应付代扣税功能需完成3个层级12个核心步骤:1)全局激活公司代码代扣税功能;2)配置代扣税规则、税率和科目,包括定义税种类型、代码、总账科目等;3)在供应商/客户主数据中关联代扣税设置。完成后系统可在发票或付款环节自动计算并过账代扣税,支持多税种并行计算和税率年度调整,最终生成税务报表。常见问题排查需检查公司代码激活状态和主数据配置。(149字)

金牌架构师 836

POJ1113 计算几何-凸包算法-卷包裹法、Graham-Scan法

POJ1113 wall 题目链接:http://poj.org/problem?id=1113 凸包算法的板题,找出凸包,计算凸包的周长加上以要求的距离为半径的圆的周长即可。 卷包裹法 思路: 点集预处理,以横坐标为准从小到大(横坐标相同以纵坐标从小到大) 从点集的第一个点开始找上凸包。 如果要添加的点在凸包的点集中最新添加的两个点所形成的直线的右边,将改点添加进凸包的点集。 如果在左边,把...

Aczy156的博客 427

A2A 协议详解:Agent Card 的设计与实现

Agent Card 是 Agent2Agent (A2A) 协议中实现智能体发现与互操作性的核心组件。本文将深入剖析 Agent Card 的设计理念、关键字段及其在智能体生态系统中的作用。我们将通过详细的 JSON Schema 解析和 Python SDK 示例,帮助您理解如何精确地定义和发布智能体能力,为构建可发现、可协作的 AI 智能体奠定基础。当您使用a2a.Agent类初始化一个智能体时,SDK 会根据您提供的参数(nameversion等)自动构建内部的 Agent Card 表示。

加入“Super Entity”,与全能开发团队共探AI智能体与数字人项目,开启前沿技术之旅。 1476

Win10系统怎么打开Microsoft帐户?Win10系统打开Microsoft的帐户方法

也被加入了越来越多的功能,我们在使用电脑的时候,很对用户会打开Micorsofy账户功能,搜索个人邮件信息,照片等等,还能将个人的数据备份到账户内,那要怎么打开账户呢,下面带给大家方法。以上就是小编给大家整理的win10系统打开Microsoft帐户的具体操作方法,方法简单易懂,有需要的朋友可以看一看,希望这篇教程对大家有所帮助。5、最后我们将“Microsoft帐户”选项下方的开关按钮向右滑动将其打开,如下图所示,这样就成功打开wMicrosoft帐户功能了。我们在窗口左侧点击“设置”选项即可。

2401_88800025的博客 278

poj1113(凸包Graham算法)

//Graham算法 //poj1113此题点坐标为int型 #include #include #include #include using namespace std; #define maxn 1100 const double pi=acos(-1.0); struct Point{ int x,y; }s[maxn]; int st[maxn],top; int cross(

zizahn的博客 515

第一部分:VTK基础入门(第1章:VTK简介与概述)

VTK简介与核心特性概述 VTK(Visualization Toolkit)是一个开源的跨平台C++类库,专用于3D计算机图形学、图像处理和科学可视化。由Kitware公司开发,VTK自1993年起源以来,经历了开源化、成熟化和现代化多个发展阶段,现已成为科学可视化的核心工具之一。 VTK的核心特性包括: 管道架构:模块化设计实现数据流管理 丰富的数据支持:处理多边形数据、图像数据等 强大的渲染能力:集成OpenGL,支持多种渲染技术 最新版本VTK 9.4.2增强了现代C++支持,优化了内存管理,并提升

仰望星空的博客 2362

ACM-计算几何之Wall——poj1113

ACM 计算几何 Wall poj1113 求凸包周长

继续激情,继续奋斗。 1892

温度PID控制PLC程序

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

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

计算几何 POJ 1113 Wall

Problem Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King’s castle. The King was so greedy, that he would not listen to his Architect’s proposals...

FrankDura的博客 571

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

【POJ1113】【计算几何】Wall 题解

Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King’s castle. The King was so greedy, that he would not listen to his Architect’s proposals to build

It's Maverick. 825

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

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

[计算几何]Wall[POJ1113]/[UVA1303]

欢迎大家访问我的老师的OJ———caioj.cn 题面描述 POJ UVA 思路 简要题意大概就是: 给定n,l, 然后给定平面中n个点的横纵坐标, 求一个最小周长的封闭图形(可以包含曲线), 要求该图形包裹住所有点, 并且该封闭图形上的任何点距离任意给定点不小于l 输出这个最小周长 就以样例为例吧: 很明显,这个封闭图形的最小周长就为凸包周长加2πl2\pi l2πl。 AC code 此...

lb2003 305

[POJ1113] Wall && 计算几何

求凸包 最后加上一个圆的周长即可 #include #include #include #include #include #include #define fabs(x) ((x) < 0 ? (-(x)) : (x)) #define SF scanf #define PF printf using namespace std; typedef long l

shiyukun1998的专栏 448

POJ - 1113 Wall 【计算几何凸包】

Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King’s castle. The King was so greedy, that he would not listen to his Architect’s proposals to buil...

slass-mot-odet 456

POJ1113Wall(计算几何基础)

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25657   Accepted: 8532 Description Once upon a time there was a greedy King who ordered his chief Architect to build a wal

Achiberx 2101

【计算几何】poj1113 Wall

进行凸包扫描并求面积即可。 #include #include #include #include using namespace std; struct Point{ int x,y; }; int cmp(const void*elem1 ,const void*elem2); void add(Point a,int k); double dbl(Point a,Point b,Poi

BananaTree 741

【计算几何】【求凸包】【POJ 1113】wall

题目大意: 多朵夺舵剁垛跺惰堕掇哆驮度躲踱沲咄铎裰哚缍亸仛兊兑兑。(乱码) 其实就是求个凸包,围墙在的相对原来点距离为L  — 就是加个半径为L的圆面积——  想一想,为什么。 都比较正常,加几个注释,没有特别解释的。补充一句,计算几何的精度判断是比较必要的,eps要用起来,注意。(这道里面我没用) #include #include #include #include #includ

w532656205的专栏 453

【计算几何/凸包】POJ 1113 Wall

Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King’s castle. The King was so greed...

落花水面 448

poj1113——Wall(计算几何凸包)

Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25236Accepted: 8409 Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall around

JIA_char 701

poj 1113 Wall (计算几何)

Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35284   Accepted: 12007 Description Once upon a time there was a greedy King who ordered his chief Archi

clover_hxy的博客 532

POJ 1113 Wall 题解 《挑战程序设计竞赛》

为什么80%的码农都做不了架构师?>>> ...

weixin_33881753的博客 286
上一篇: POJ - 2398 Toy Storage————计算几何
下一篇: POJ - 3348Cows ————计算几何(凸包计算)
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值