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

Re:zju ac到这re了帮忙看看

Posted by 041221125 at 2006-03-08 18:47:06 on Problem 2609
In Reply To:zju ac到这re了帮忙看看 Posted by:daringQQ at 2006-02-06 22:28:00
> // zj1859.cpp : Defines the entry point for the console application.
> //
> 
> #include <stdio.h>
> #include <memory.h>
> 
> int len[1000],reach[10001];
> bool pos[1000];
> 
> int min(int a,int b){
> 	return a<b ? a:b;
> }
> int main(int argc, char* argv[])
> {
> 	int length,n,sum,i,j,p;
> 	bool flag;
> 	while(scanf("%d",&length) != EOF){
> 		length*=100;
> 		memset(reach,0,sizeof(reach));
> 		memset(pos,false,sizeof(pos));
> 		reach[0]=1;
> 		n=1;
> 		while(scanf("%d",&len[n]),len[n]) n++;
> 		n--;
> 		sum=0;
> 		for(i=1;i<=n;i++){
> 			for(j=min(sum,length-len[i]);j>=0;j--)
> 				if(reach[j]>0 && reach[j+len[i]]==0) reach[j+len[i]]=i;
> 			sum+=len[i];
> 			if(sum>length*2) break;
> 			flag=false;
> 			for(j=sum/2;j>=0;j--)
> 				if(reach[j]>0 && sum-j<=length){
> 					flag=true;
> 					p=j;
> 					break;
> 				} 
> 			if(!flag) break;
> 		}
> 		while(p>0){
> 			pos[reach[p]]=true;
> 			p-=len[reach[p]];
> 		}
> 		printf("%d\n",i-1);
> 		for(j=1;j<i;j++){
> 			if(!pos[j]) printf("port\n");
> 			else printf("starboard\n");
> 		}
> 	}
> 	return 0;
> }


在sum=0;一句处加一句p=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