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 jiang_acm at 2010-03-28 21:39:02 on Problem 1135
#include <stdio.h>
#include <climits>
typedef int* IntArrayPtr;
int main()
{
	int n,m;
	int j=0;
	while(scanf("%d%d",&n,&m)!=EOF && !(n==0 && m==0))
	{
		int ii,jj;
		if(n==1)
		{		
			j++;
			printf("System #%d\nThe last domino falls after 0.0 seconds, at key domino 1.\n\n",j);
			continue;
		}
		IntArrayPtr *cell = new IntArrayPtr[n+1];
		int *d = new int[n+1];
		bool *final = new bool[n+1];
		for(int i5 = 0;i5<n+1;i5++)
			final[i5] = false;
		for(int i1 = 0;i1<n+1;i1++)
		{
			cell[i1] = new int[n+1];
		}
        for(int i3 = 1;i3<n+1;i3++)
			for(int i4=1;i4<n+1;i4++)
			{
				//cell[i3][i4] = -1;
				cell[i3][i4] = INT_MAX;
			}
		int n1,n2,time;
		for(int i15=0;i15<m;i15++)
		{
			scanf("%d%d%d",&n1,&n2,&time);
			if(n1>n2)
			{
				int temp = n1;
				n1 = n2;
				n2 = temp;
			}
			cell[n1][n2] = time;
		}
		int cell_max = 0;
		/*for(int i9 = 1;i9<n+1;i9++)
			for(int i10=1;i10<n+1;i10++)
			{
				if(cell[i9][i10]>cell_max)
				{
					cell_max = cell[i9][i10];
				}
			}
		for(int i11 = 1;i11<n+1;i11++)
		{
			for(int i12=1;i12<n+1;i12++)
			{
				if(cell[i11][i12] == -1)
				{
					cell[i11][i12] = cell_max+1;
				}
				//cout<<cell[i11][i12]<<" ";
			}
			//cout<<endl;
		}*/
		for(int i12=2;i12<n+1;i12++)
		{
			d[i12] = cell[1][i12];
		}
		d[1] = 0;
		final[1] = true;
		int v;
		for(int i6 = 2;i6<n+1;i6++)
		{
			int min = INT_MAX;
			for(int i7 = 2;i7<n+1;i7++)
			{
				if(!final[i7] && d[i7]<min)
				{
					v = i7;
					min = d[i7];
				}
			}
			final[v] = true;
			for(int i8 = 2;i8<n+1;i8++)
			{
				if(v>i8)
				{
					ii = v;
					jj = i8;
				}
				else
				{
					ii = i8;
					jj = v;
				}
				if(!final[i8] && d[v]+cell[jj][ii]<d[i8])
					d[i8] = d[v] + cell[jj][ii];
			}
		}
		int max = 0;
		for(int t1=1;t1<n+1;t1++)
		{
			if(d[t1]>max)
				max = d[t1];
		}
		int *times = new int[n+1];
		for(int j1=1;j1<n+1;j1++)
		{
			times[j1] = max-d[j1];
			//cout<<d[j1]<<" "<<endl;
		}
		bool flag = false;
		double sum = 0;
		for(int j2 = 1;j2<n+1;j2++)
		{
			for(int j3=j2+1;j3<n+1;j3++)
			{
				if(cell[j2][j3]!=INT_MAX && (cell[j2][j3]-times[j2]-times[j3]>0) && (cell[j2][j3]-times[j2]-times[j3])/2.0>sum)
				{
					flag = true;
					sum = (cell[j2][j3]-times[j2]-times[j3])/2.0;
					ii = j2;
					jj = j3;
				}
			}
		}
		if(flag)
		{
			j++;
			printf("System #%d\nThe last domino falls after %.1f seconds, between key dominoes %d and %d.\n\n",j,d[n]+sum,ii,jj);
		}
		else
		{
			j++;
			printf("System #%d\nThe last domino falls after %.1f seconds, at key domino %d.\n\n",j,d[n]+sum,n);
		}
		for(int j = 0;j<n+1;j++)
		{
			delete []cell[j];
		}	
		delete []cell;
		delete []d;
		delete []final;
		delete []times;
	}
	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