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

为什么总是WA呢?有谁能给几个容易出错的数据啊

Posted by 00448130 at 2005-04-28 18:58:39 on Problem 1042
#include <iostream.h>

void main()
{
	int n, h ;
	cin >> n ;
	int test = 0;
	while (n)
	{
		test ++ ;
		cin >> h;
		int hh = 60 * h ;
		int * f = new int[n+1] ;
		int * d = new int[n+1] ;
		int * t = new int[n] ;
		int i ;
		for ( i = 1; i <= n; i++ )                   cin >> f[i] ;
		for ( i = 1; i <= n; i++ )                   cin >> d[i] ;
		for ( i = 1; i <= n-1; i++ )                   cin >> t[i] ;

		int x ;//最多走到湖泊几
		int * time = new int[n+1] ;//每种情况时花费在每个湖的时间
		
		for ( i = 1; i <= n; i++ )        time[i] = 0;

		int * answer = new int[n+1] ,num = 0, length = 0 ;      //输出结果的每个湖泊的用时
		for ( i = 1; i <= n; i++ )          answer[i] = 0 ;
		for ( x = 1; x <= n; x++ )
		{
			for ( i = 1; i <= n; i++ )        time[i] = 0;
			int * ff = new int[n+1] ;
			for ( i = 1; i <=n; i++ )              ff[i] = f[i] ;
			int fish = 0 ;//每种情况得到的鱼
			hh = 60 * h ;
			for ( i = 1; i < x; i++ )              hh -= t[i] * 5 ;
			if (hh < 0)              continue ;//剪枝,直接去掉不可能的情况
			if (hh == 0)             time[1] = 60 * h ; 

			for ( ; hh > 0 ; hh -= 5 )
			{
				int most = ff[1] , numOfMost = 1 ;
				for ( i = 2; i <= x; i++ )
				{
					if (ff[i] > most)
					{ most = ff[i];       numOfMost = i ; }
				}
				if (most == 0)                 
				{
	 				time[1] += hh ;
					hh = 0 ;
					break ;//每个湖里面都没有鱼了
				}
				time[numOfMost] += 5 ;
				if (ff[numOfMost] <= d[numOfMost])    
				{
					fish += ff[numOfMost] ;
					ff[numOfMost] = 0 ;
				}
				else
				{
					fish += most ;
					ff[numOfMost] -= d[numOfMost] ;
				}
		//		delete [] ff ;
				
			}
			
			if (fish > num) //两组一样多的鱼..,改
			{
				for ( i = 1; i <=x; i++ )              answer[i] = time[i] ;
				num = fish ;
				length = x ;
			}
			if (fish == num)
			{
				for ( i = 1; i <= x; i++ )
				{
					if (time[i] < answer[i])         break;
				}
				if (i == x )
				{
					for ( i = 1; i <=x; i++ )              answer[i] = time[i] ;
					num = fish ;
					length = x ;
				}
				
			}
		}
		if (test!=1)    cout << endl ;
		for ( i = 1; i <n ; i++ )
		{
			cout << answer[i] << ", " ;
		}
		cout << answer[n] << endl;
		cout << "Number of fish expected: " << num << endl ;
		cin >> n ;
//		delete []f;
//		delete []d;
//		delete []t;
//		delete []time;
//		delete []answer;
	}

}

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