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

感觉和AC的代码是一回事啊,为什么总是WA?

Posted by yeknight at 2009-03-07 13:05:02 on Problem 1042
别人AC的代码:
#include<iostream>

using namespace std;

int main()

{

       int i,j,k,g,n,h,ans,tot,tt=0,f[32],d[32],t[32],now[32],tnow[32],times[32];

       while (scanf("%d",&n),n)

       {

              if (tt++)

                     printf("\n");

              scanf("%d",&h);

              h*=12;

              for (i=0;i<n;++i)

              {

                     scanf("%d",&f[i]);

                     now[i]=f[i];

              }

              for (i=0;i<n;++i)

                     scanf("%d",&d[i]);

              for (i=0;i<n-1;++i)

                     scanf("%d",&t[i]);

              memset(times,0,sizeof(times));

              for (ans=i=0;i<n&&h>0;++i)

              {

                     for (j=0;j<i;++j)

                            now[j]=f[j];

                     memset(tnow,0,sizeof(tnow));

                     for (tot=k=0;k<h;++k)

                     {

                            for (g=0,j=1;j<=i;++j)

                                   if (now[j]>now[g])

                                          g=j;

                            tot+=now[g];

                            now[g]-=d[g];

                            if (now[g]<0)

                                   now[g]=0;

                            ++tnow[g];

                     }

                     if (tot>ans)

                     {

                            ans=tot;

                            for (j=0;j<n;++j)

                                   times[j]=tnow[j];

                     }

                     else if (tot==ans)

                     {

                            for (j=0;j<n;++j)

                                   if (tnow[j]!=times[j])

                                          break;

                            if (j<n&&tnow[j]>times[j])

                                   for (g=j;g<n;++g)

                                          times[g]=tnow[g];

                     }

                     h-=t[i];

              }

              for (i=0;i<n-1;++i)

                     printf("%d, ",times[i]*5);

              printf("%d\nNumber of fish expected: %d\n",times[n-1]*5,ans);

       }

       return 0;

}

我的代码:
#include <iostream>
using namespace std;

int main()
{
	int n,h;
	int f1[26],f[26],t[26],d[26],lake_time1[26],lake_time[26];
	int i,j,Ltime,max_lake;
	int k,total,total_fish=0;
	bool flag=false;

	cin>>n;
	while(n)
	{
		cin>>h;
		for(i=1; i<=n; ++i)
		{
			cin>>f[i];
			f1[i] = f[i];
		}
		for(i=1; i<=n; ++i)
		{
			cin>>d[i];
			lake_time[i] = 0;
		}
		for(i=1; i<n; ++i)
		{
			cin>>t[i];		
		}
		
		for(i=1; i<=n; ++i)
		{
			total = 0;
			Ltime = h * 60;
			for(j=1; j<i; ++j)
			{
				Ltime = Ltime - t[j] * 5;		
			}
			if(Ltime < 0)
				break;
			for(j=1; j<=i; ++j)
			{
				f1[j] = f[j];
				lake_time1[j] = 0;
			}
			max_lake = f1[1];
			k = 1;
			while(Ltime > 0)
			{
				max_lake = f1[1];
				k = 1;
				flag = false;
				for(j=1; j<=i; ++j)
				{
					if(f1[j] < 0)
						f1[j] = 0;
					if(max_lake < f1[j])
					{
						k = j;
						max_lake = f1[j];
					}
					if(f1[j])
						flag = true;
				}
				if(false == flag)
				{
					lake_time1[1] += Ltime;
					break;
				}
				if(max_lake > 0)
				{
					lake_time1[k] += 5;
					total += f1[k];
					f1[k] = f1[k] - d[k];
					Ltime -= 5;
				}
				else if(max_lake == 0)
				{
					lake_time1[0] += 5;
					Ltime -= 5;
				}
				else
				{
					lake_time1[0] += 5;
					Ltime -= 5;
					lake_time1[k] = 0;

				}	
			}
			if(total > total_fish)
			{
				total_fish = total;
				for(j=1; j<=i; j++)
				{
					lake_time[j] = lake_time1[j];
				}
			}
			else if(total == total_fish)
			{
				for(j=1; j<=i; ++j)
				{
					if(lake_time1[j] > lake_time[j])
					{
						for(j=1; j<=i; j++)
						{
							lake_time[j] = lake_time1[j];
						}
						break;
					}
					else if(lake_time1[j] < lake_time[j])
						break;
				}
			}
		}
		for(i=1; i<n; ++i)
			cout<<lake_time[i]<<", ";
		cout<<lake_time[n]<<endl;
		cout<<"Number of fish expected: "<<total_fish<<endl;
		cout<<endl;
		cin>>n;
	}
	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