Car refueling problem "a car can travel n kilometres after filling it with oil. There are K gas stations on the trip. To make the least amount of refueling along the way, design an effective algorithm that points out where to refuel at those gas stations. Data input: The input data is given by the file input.txt. The first line has 2 positive integers n and K, which means that the car can travel NKM after filling with oil, and there are K gas stations on the road. In the next 1 lines, there is a k+1 integer representing the distance between the K gas station and the first K-1 gas station. The No. 0 gas station said the departure, the car has been filled with oil. The first K+1 gas station represents the destination. Result output: The minimum number of refueling times calculated by the program is output to the file ouput.txt. If the destination cannot be reached, the "No Solution" is output. Input file Sample output File Sample Input.txt output.txt &NBS P  4 3 4 5 1 6 6 requirements: using greed algorithm, programmed to calculate and output the minimum number of refueling times, and pointed out that the gas stations should be docked refueling.
#include <stdio.h> int main () {file *fp;//pointer int a[100],b[100];
int i,n,k,flag,sum,count,temp;
Fp=fopen ("Input.txt", "R"); if (fp==null) {printf ("The file cannot be opened.)
\ n ");
Exit (0);
} flag=0;
i=0;
Temp=1;
while (!feof (FP)) {if (flag==0) fscanf (FP, "%d%d", &n,&k);//read from file N,k flag=1; if (flag!=0) {fscanf (FP, "%d", &a[i++])//read from the file the distance between the gas stations if (A[I]>N)//IF
The distance between two stations is greater than N, then the destination temp=0 cannot be reached;
} fclose (FP);
if (temp==0) {Fp=fopen ("Output.txt", "w");
fprintf (FP, "No Solution");
Fclose (FP);
return 0;
} count=0;
sum=0;
for (i=0; i<k+1; i++) {sum+=a[i];
if (sum>n) {i--;
b[count++]=i+1;
sum=0;
} fp=fopen ("Output.txt", "w");
fprintf (FP, "%d", count);//write the data to the file fclose (FP); REturn 0;
}