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

没理由的啊~~~怎么就TLE了?!!!(贪心)

Posted by liao14 at 2007-04-25 13:39:05 on Problem 1042
#include<stdio.h>

int main()
	{
		int h,n,f[26],d[26],t[25];
		
		while(1)
			{
				scanf("%d",&n);
				if(!n)break;
				scanf("%d",&h);
				int i,j;
				for(i=1;i<=n;i++) scanf("%d",&f[i]);
				for(i=1;i<=n;i++) scanf("%d",&d[i]);
				for(i=1;i<n;i++) scanf("%d",&t[i]);
				
				long fish=0;
				int time[26]={0};
				for(i=1;i<=n;i++)
					{
						int times=h*12;
						for(j=1;j<i;j++) times-=t[j];
						int fishtmp=0,timetmp[26]={0},ftmp[26];
						for(j=1;j<=i;j++) ftmp[j]=f[j];
						while(times--)
							{
								int max=1;
								for(j=2;j<=i;j++)
									if(ftmp[j]>ftmp[max]) max=j;
								fishtmp+=ftmp[max];
								if(ftmp[max]>0) ftmp[max]-=d[max];
									else ftmp[max]=0;
								timetmp[max]+=5;
							}
						if(fishtmp>fish)
							{
								fish=fishtmp;
								for(j=1;j<=n;j++)
									time[j]=timetmp[j];
							}
					}
				printf("%d",time[1]);
				for(i=2;i<=n;i++)printf(" ,%d",time[i]);
				printf("\n");
				printf("Number of fish expected: %d\n",fish);
			}
		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