Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

再次通知,小心数组范围!附代码

Posted by woshiliyiyiyiyi at 2012-08-12 09:52:30 on Problem 2365
#include<stdio.h>
#include<math.h>
#define N 100
#define PI 3.141592653589

struct point
{
	double a, b;
};

double distance(struct point s, struct point t)
{
	return sqrt(pow(s.a-t.a, 2) + pow(s.b-t.b, 2));
}

int main()
{
	int M, i;
	double redium;
	struct point value[N];	
	double sum;
	
	while (fscanf(stdin, "%d %lf", &M, &redium) != EOF)
	{
		sum = 2 * PI * redium;
		
		fscanf(stdin, "%lf %lf", &value[0].a, &value[0].b);
		for (i=1; i<M; i++)
		{
			fscanf(stdin, "%lf %lf", &value[i].a, &value[i].b);
			sum += distance(value[i], value[i-1]);
		}
		sum += distance(value[i-1], value[0]);
		
		printf("%.2lf\n", sum);
	}
	
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator