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

相同代码C++WA,G++就AC了。。。顺便贴下代码(贪心加枚举)

Posted by hdd871532887 at 2016-01-02 18:11:13 on Problem 1042 and last updated at 2016-01-02 19:07:24
#include<stdio.h>
#include<algorithm>
using namespace std;
int fi[30];
int di[30];
int ti[30];
int cfi[30];
int n,t;
struct st
{
	int max;
	int num[30];
}s[30];
int getmax(int p[],int i,int j)
{
	int t=i,cmax=p[i];
	for(int m=i+1;m<=j;m++)
    {
    	if(cmax<p[m])
    	{
    		cmax=p[m];
    		t=m;
		}
	}
	return t;
}
void fishing()
{
	int T,v;
	for(int i=1;i<=n;i++)
	{
		s[i].max=0;
		for(int j=1;j<=n;j++)
		{
			s[i].num[j]=0;
		}
	}
	for(int i=1;i<=n;i++)//i表示结束钓鱼时的湖
	{
		v=0;
		T=t*60;
		for(int j=1;j<=i;j++)
		{
			cfi[j]=fi[j];
			T=(j<i)?T-ti[j]*5:T;
		}
		while(v<T)
		{
			int k=getmax(cfi,1,i);// 找到当前状态下捕鱼最多的湖进行捕鱼 
			s[i].max+=cfi[k];
			s[i].num[k]+=5;
			cfi[k]>=di[k]?cfi[k]-=di[k]:cfi[k]=0;
			v+=5;
		}
	}
	for(int i;i<=n;i++)//将以编号为1-n的湖为结束钓鱼时,最多钓鱼数存入cfi数组 
		cfi[i]=s[i].max;
	int l=getmax(cfi,1,n);//找到其中钓鱼最多时的l,l即结束钓鱼时的小湖 
	for(int i=1;i<=n;i++)
	{
		if(i!=n)
		    printf("%d, ",s[l].num[i]);
		else
		    printf("%d\n",s[l].num[i]);
	}
	printf("Number of fish expected: %d\n\n",s[l].max);
}
int main()
{
	while(scanf("%d",&n),n)
	{
		scanf("%d",&t);
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&fi[i]);
		}
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&di[i]);
		}
		for(int i=1;i<n;i++)
		{
			scanf("%d",&ti[i]);
		}
		fishing();
	}
 } 

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