#include <stdio.h>
#include <stdlib.h>
main()
{
int *jump=NULL;
int i,j,k,length,min,max,stone_num,temp,minous,total,counter=0,tag=0,m,n=1,flag=0;
int a[100];
printf("Please input the length of the bridge:\n");
scanf("%d",&length);
jump=(int *)malloc(sizeof(int)*(length+1));
for(i=0;i<length;i++)
*(jump+i)=0;
printf("Please input the minium pace and the maxnium pace:\n");
scanf("%d%*c%d",&min,&max);
printf("Please input the number of the stones:\n");
scanf("%d",&stone_num);
printf("Now enter the place of the stones:\n");
for(i=0;i<stone_num;i++)
{
scanf("%d",&temp);
*(jump+temp)=1;
}
for(i=0;i<min;i++)
*(jump+i)=-1;
if(2*min>max)
for(i=max+1;i<2*min;i++)
*(jump+i)=-1;
for(i=2*min;i<=length-1;i++)
{
for(j=i-max;j<=i-min;j++)
{
if(j<0) continue;
if(*(jump+j)!=-1)
{
if(counter==0)
{
minous=*(jump+j);
counter++;
}
else minous=*(jump+j)>minous?minous:*(jump+j);
}
else tag++;
}
counter=0;
if(tag==max-min+1)
*(jump+i)=-1;
else *(jump+i)+=minous;
tag=0;
}
a[0]=length;
do {
for(k=length-max;k<=length-1;k++)
{
if(*(jump+k)!=-1)
{
if(counter==0)
{
total=*(jump+k);
m=k;
counter++;
}
else if(total>*(jump+k))
{
total=*(jump+k);
m=k;
}
}
}
counter=0;
if(flag==0)
{
printf("%d\n",total);
flag=1;
}
a[n++]=length=m;
} while(m>max);
a[n]=0;
for(i=n;i>=0;i--)
{
if(i!=0)
printf("%d->",a[i]);
else printf("%d",a[i]);
}
free (jump);
getch();
}
OK,搞定了。这个程序就研究到这,花费太多时间了.
#include <stdlib.h>
main()
{
int *jump=NULL;
int i,j,k,length,min,max,stone_num,temp,minous,total,counter=0,tag=0,m,n=1,flag=0;
int a[100];
printf("Please input the length of the bridge:\n");
scanf("%d",&length);
jump=(int *)malloc(sizeof(int)*(length+1));
for(i=0;i<length;i++)
*(jump+i)=0;
printf("Please input the minium pace and the maxnium pace:\n");
scanf("%d%*c%d",&min,&max);
printf("Please input the number of the stones:\n");
scanf("%d",&stone_num);
printf("Now enter the place of the stones:\n");
for(i=0;i<stone_num;i++)
{
scanf("%d",&temp);
*(jump+temp)=1;
}
for(i=0;i<min;i++)
*(jump+i)=-1;
if(2*min>max)
for(i=max+1;i<2*min;i++)
*(jump+i)=-1;
for(i=2*min;i<=length-1;i++)
{
for(j=i-max;j<=i-min;j++)
{
if(j<0) continue;
if(*(jump+j)!=-1)
{
if(counter==0)
{
minous=*(jump+j);
counter++;
}
else minous=*(jump+j)>minous?minous:*(jump+j);
}
else tag++;
}
counter=0;
if(tag==max-min+1)
*(jump+i)=-1;
else *(jump+i)+=minous;
tag=0;
}
a[0]=length;
do {
for(k=length-max;k<=length-1;k++)
{
if(*(jump+k)!=-1)
{
if(counter==0)
{
total=*(jump+k);
m=k;
counter++;
}
else if(total>*(jump+k))
{
total=*(jump+k);
m=k;
}
}
}
counter=0;
if(flag==0)
{
printf("%d\n",total);
flag=1;
}
a[n++]=length=m;
} while(m>max);
a[n]=0;
for(i=n;i>=0;i--)
{
if(i!=0)
printf("%d->",a[i]);
else printf("%d",a[i]);
}
free (jump);
getch();
}
OK,搞定了。这个程序就研究到这,花费太多时间了.
对不礼貌的女生收钱......