c++的题目

来源:百度知道 编辑:UC知道 时间:2024/06/03 23:51:53
(vijos上的)

背景 Background
平面上有N个圆柱形的大钉子,半径都为R,所有钉子组成一个凸多边形。
现在你要用一条绳子把这些钉子围起来,绳子直径忽略不计。

描述 Description
求出绳子的长度

输入格式 Input Format
第1行两个数:整数N(1<=N<=100)和实数R。
接下来N行按逆时针顺序给出N个钉子中心的坐标
坐标的绝对值不超过100。

输出格式 Output Format
一个数,绳子的长度,精确到小数点后2位。

请问怎么做 要详细代码

/*输入文件:d:\\1.txt
4 5.6
100 100
100 200
200 200
200 100
*/

#include <fstream>
#include <iostream>
using namespace std;

#include <stdlib.h>
#include <math.h>

struct point
{
int x;
int y;
};

int N;//钉数
double radius;//半径

double distance(point a, point b, point c);

int main(int argc, char *argv[])
{
int i, j = 0, count = 0;
double sum = 0;;
char t[10];
char str[10];
ifstream ifile("d:\\1.txt");
ifile.getline(str, 10);//读入第一行

for (i = 0; str[i] != ' '; i++)//求N值
{
t[i] = str[i];
}

N = atoi(t);

i += 1; //求radius
for (; (str[i] > '0' && str[i] < '9') || str[i] == '.'; i++)
{
t[j++] = str[i];
}