当前位置: 首页 > news >正文

poj解题报告——poj 2365 Rope

原题入口

poj 2365 Rope

题目描述

Rope
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7372 Accepted: 2587

Description
Plotters have barberically hammered N nails into an innocent plane shape, so that one can see now only heads. Moreover, pursuing their mean object, they have hammered all the nails into the vertices of a convex polygon. After that they…it is awful… have roped off the nails, so that the shape felt upset (the rope was very thin). They’ve done it as it is shown in the figure.

Your task is to find out a length of the rope.

Input
There two numbers in the first line of the standard input: N — a number of nails (1 <= N <= 100), and a real number R — a radius of heads of nails. All the heads have the same radius. Further there are N lines, each of them contains a pair of real coordinates (separated by a space) of centers of nails. An absolute value of the coordinates doesn’t exceed 100. The nails are described in a clockwise order starting from an arbitrary nail. Heads of different nails don’t adjoin.

Output
The standard output should contain in its only line a real number with two digits precision (after a decimal point) — a length of the rope.

Sample Input

4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0

Sample Output

14.28

Source
Ural State University Internal Contest October’2000 Junior Session

解题代码

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

#define PI  3.141592653
#define NAIL_COUNT  100
double arNailPos[NAIL_COUNT][NAIL_COUNT] = {0};

double GetLenByPos(double x1, double y1, double x2, double y2)
{
    return sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
}

int main()
{
    int N;                  // 钉子数
    double dR;              // 钉子半径
    double dRopeLength = 0; // 绳子长度
    cin >> N >> dR;
    cin >> arNailPos[0][0] >> arNailPos[0][1];

    for (int nIndex = 1; nIndex < N; ++nIndex)
    {
        cin >> arNailPos[nIndex][0] >> arNailPos[nIndex][1];
        dRopeLength += GetLenByPos(arNailPos[nIndex - 1][0], arNailPos[nIndex - 1][1], arNailPos[nIndex][0], arNailPos[nIndex][1]);
    }

    dRopeLength += GetLenByPos(arNailPos[N - 1][0], arNailPos[N - 1][1], arNailPos[0][0], arNailPos[0][1]);
    dRopeLength += 2 * PI * dR;

    cout.setf(ios::fixed);  
    cout << fixed << setprecision(2) << dRopeLength << endl; // 输出绳子长度保留2位小数,不足两位填充0

    return 0;
}

解题过程

  • 题意:在一个平面上钉N个钉子,每个钉子有一个半径R,求这N个钉子构成的凸多边形周长是多少

  • 思路:将N个钉子构成的线段依次加起来就行,注意加上钉子上缠绕绳子的长度,其实就是一个钉子的周长

提交结果

poj2365

相关文章:

  • poj解题报告——poj 2575 Jolly Jumpers
  • poj解题报告——poj 3536 Beer Refrigerator
  • poj解题报告——poj 1528 Perfection
  • SVN:Fully recursive、Working copy和Immediate children...区别
  • ... fatal error LINK1120:1个无法解析的外部命令 的解决办法
  • UE4蓝图中的常用操作
  • UE4引擎查看资源相互引用的情况
  • UE4引擎Bulid打包失败UnrealBuildTool Exception: System.IO.IOException:
  • UE4引擎Android打包只生成apk而不需要obb文件
  • UE4引擎学习笔记:Blueprints Visual Scripting-Basic Scripting
  • C/C++位域(位段)示例总结
  • mysql 诡异的1054错误
  • UE4引擎取消编辑器处于后台时的降帧选项
  • Lua的函数参数为table时奇特现象
  • UE4引擎自定义插件导出类定义的简单流程
  • JavaScript 如何正确处理 Unicode 编码问题!
  • HTML-表单
  • JavaScript服务器推送技术之 WebSocket
  • Javascript基础之Array数组API
  • java中具有继承关系的类及其对象初始化顺序
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • python学习笔记 - ThreadLocal
  • React系列之 Redux 架构模式
  • 理解在java “”i=i++;”所发生的事情
  • 问:在指定的JSON数据中(最外层是数组)根据指定条件拿到匹配到的结果
  • 我的面试准备过程--容器(更新中)
  • 限制Java线程池运行线程以及等待线程数量的策略
  • 新手搭建网站的主要流程
  • 用element的upload组件实现多图片上传和压缩
  • Java总结 - String - 这篇请使劲喷我
  • 宾利慕尚创始人典藏版国内首秀,2025年前实现全系车型电动化 | 2019上海车展 ...
  • ​猴子吃桃问题:每天都吃了前一天剩下的一半多一个。
  • # Pytorch 中可以直接调用的Loss Functions总结:
  • #pragma once与条件编译
  • $(function(){})与(function($){....})(jQuery)的区别
  • $forceUpdate()函数
  • %3cscript放入php,跟bWAPP学WEB安全(PHP代码)--XSS跨站脚本攻击
  • (14)Hive调优——合并小文件
  • (14)学习笔记:动手深度学习(Pytorch神经网络基础)
  • (2009.11版)《网络管理员考试 考前冲刺预测卷及考点解析》复习重点
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (原創) 如何優化ThinkPad X61開機速度? (NB) (ThinkPad) (X61) (OS) (Windows)
  • .bashrc在哪里,alias妙用
  • .NET CORE 3.1 集成JWT鉴权和授权2
  • .net core控制台应用程序初识
  • .NET WebClient 类下载部分文件会错误?可能是解压缩的锅
  • .NET 中小心嵌套等待的 Task,它可能会耗尽你线程池的现有资源,出现类似死锁的情况
  • .net解析传过来的xml_DOM4J解析XML文件
  • .stream().map与.stream().flatMap的使用
  • @staticmethod和@classmethod的作用与区别
  • [<MySQL优化总结>]
  • [Android]常见的数据传递方式
  • [BZOJ5250][九省联考2018]秘密袭击(DP)
  • [C#基础知识]专题十三:全面解析对象集合初始化器、匿名类型和隐式类型
  • [Flutter]WindowsPlatform上运行遇到的问题总结