汽车加油问题

``````7 7
1 2 3 4 5 1 6 6``````

``4``

``````#include<stdio.h>
#define MAX_NUM 1010
int array[MAX_NUM];
int n,k;
int greedy()
{
int start = 0;
int total = 0;
int rest_oil = n;
while(start <= k)
{
if(rest_oil < array[start])
{
rest_oil = n;
++total;
if(rest_oil < array[start])
break;
}
rest_oil -= array[start];
++start;

}
if(start != k + 1)
return -1;
else
}
int main()
{
int i;
int result = 0;
scanf("%d%d",&n,&k);
for( i = 0;i <= k;++i)
{
scanf("%d",&array[i]);
}
result = greedy();
if(result == -1)
printf("No Solution!\n");
else
printf("%d\n",result);
return 0;
}``````

``````#include<stdio.h>
int minmin(int a,int b)
{
if (a>=b) return b;
else return a;
}
int main()
{
int n,k,dis[1010],i,j,min=20000,num,time=0;
long long int sum=0;
scanf("%d %d\n",&n,&k);
for (i=1;i<=k+1;i++)
{
scanf("%d",&dis[i]);
if (dis[i]>n) {printf("No Solution!");return 0;}
sum+=dis[i];
}
num=n;
for (i=1;i<=k+1;i++)
if (num>=dis[i]) num=num-dis[i];
else {num=n-dis[i];time=time+1;}

if (sum<=n) time=0;
printf("%d",time);
return 0;
}
``````