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

为什么我用优先队列优化的Prime会超时啊?反而N^2的能过。。大牛帮忙看看

Posted by huangwei at 2007-09-12 20:11:45 on Problem 2728
double prime() {
	double cost = 0;
	double len = 0;
	int i,j;
	priority_queue<node> pq;
	memset(vis, 0, sizeof(vis));
	node now;
	now.s = 0;
	vis[0] = true;
	for(i=1;i<n;i++) {
		now.t = i;
		now.dis = abs(vi[0].z-vi[i].z) - rate*dist[0][i];
		pq.push(now);
	}
	while(!pq.empty()) {
		now = pq.top();
		pq.pop();
		if(vis[now.t]) continue;
		vis[now.t] = true;
		len += dist[now.s][now.t];
		cost += abs(vi[now.s].z-vi[now.t].z);
		node next;
		next.s = now.t;
		for(i=1;i<n;i++) {
			if(!vis[i]) {
				next.t = i;
				next.dis = abs(vi[next.s].z-vi[next.t].z) - rate*dist[next.s][next.t];
				pq.push(next);
			}
		}
	}
	return cost / len;
}

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