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 LiZhiXu at 2006-10-10 22:50:32 on Problem 3029
#include <stdio.h>
#include <math.h>

int b[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};

typedef struct
{
	double x, y, v, a;
}Person;

Person p[9];

int n;
double mv, temp, answer;

double calc(void)
{
	int i;
	double cx, cy, t, x1, x2, xi, yi, vi, ai, dx, dy, t1, t2, t3, home, total, last;
	cx = 0, cy = 0, total = 0, last = 0;
	for(i = 1; i <= n; i++)
	{
		xi = p[b[i]].x, yi = p[b[i]].y, vi = p[b[i]].v, ai = p[b[i]].a;
		dx = xi - cx, dy = yi - cy;
		t1 = vi * vi - mv * mv;
		t2 = 2 * (dx * vi * cos(ai) + dy * vi * sin(ai));
		t3 = dx * dx + dy * dy;
		x1 = (-t2 + sqrt(t2 * t2 - 4 * t1 * t3)) / (2 * t1);
		x2 = (-t2 - sqrt(t2 * t2 - 4 * t1 * t3)) / (2 * t1);
		t = x1 > 0 ? x1 : x2;
		total += t;
		cx = xi + t * vi * cos(ai), cy = yi + t * vi * sin(ai);
		home = total + sqrt(cx * cx + cy * cy) / vi;
		if(home > last)
		{
			last = home;
		}
	}
	return last;
}

void solve(int k)
{
	int i, t;
	if(k == n)
	{
		temp = calc();
		if(temp < answer)
		{
			answer = temp;
		}
	}
	else
	{
		for(i = k; i <= n; i++)
		{
			t = b[k]; b[k] = b[i]; b[i] = t;
			solve(k + 1);
			t = b[k]; b[k] = b[i]; b[i] = t;
		}
	}
}

int main(void)
{
	int i;
	while(scanf("%d", &n), n != 0)
	{
		scanf("%lf", &mv);
		for(i = 1; i <= n; i++)
		{
			scanf("%lf %lf %lf %lf", &p[i].x, &p[i].y, &p[i].v, &p[i].a);
		}
		answer = 1e100;
		solve(1);
		printf("%d\n", (int) (answer + 0.5));
	}
	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