| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
zju ac到这re了帮忙看看// 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;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator