Click here to Skip to main content
15,887,135 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Which one is better O(V+E) or O(ElogE)? Pin
Lauren Ragsdale3-May-18 8:06
Lauren Ragsdale3-May-18 8:06 
QuestionProblem with understanding aes gcm algorithm Pin
Member 1380418229-Apr-18 16:14
Member 1380418229-Apr-18 16:14 
AnswerRe: Problem with understanding aes gcm algorithm Pin
Richard MacCutchan29-Apr-18 21:26
mveRichard MacCutchan29-Apr-18 21:26 
GeneralRe: Problem with understanding aes gcm algorithm Pin
Member 138041821-May-18 3:41
Member 138041821-May-18 3:41 
GeneralRe: Problem with understanding aes gcm algorithm Pin
Gerry Schmitz1-May-18 5:09
mveGerry Schmitz1-May-18 5:09 
GeneralRe: Problem with understanding aes gcm algorithm Pin
Eddy Vluggen1-May-18 5:20
professionalEddy Vluggen1-May-18 5:20 
QuestionSub-Pixel Edge Detection - Implementing according to Carsten Steger's method. Pin
Member 1378530717-Apr-18 21:03
Member 1378530717-Apr-18 21:03 
QuestionProblem with variation of gas station problem. Pin
Karol Nowak16-Apr-18 2:42
Karol Nowak16-Apr-18 2:42 
I have a problem where I travel from point A to B and there is distance defined as `l`. In my car, I have a tank which can let me go only `b` kilometers. In `n` places there are gas stations and its cost for filling up my tank (I can only refill it fully). I start with a full tank.

What is the most efficient algorithm to get from the start of the highway to the end with the least cost?

My recent ideas:

Go with window sliding minimum algorithm to find (length is `b`) those stations where the cost is minimal. Code:

   int n, range, targetDist;
   scanf("%d %d %d", &n, &targetDist, &range);
   int di, ci;
   for (int k = 1; k <= n; k++)
   {
       scanf("%d %d", &di, &ci);
       D[k] = di;
       C[k] = ci;
   }
   D[0] = C[0] = bestcost[0] = 0;
   for (int i = 1; i < n+1; ++i)
   {
       bestcost[i] = 1 << 30;
       for (int j = 0; j < i; ++j)
       {
           int xx = bestcost[j] + C[i];
           if (D[i] - D[j] <= range && xx < bestcost[i])
           {
               bestcost[i] = xx;
               printf("(%d, %d)\n", i, bestcost[i]);
           }
       }
   }
Input is:

   3 8 4
   2 1
   4 2
   6 3

Output is:

   (1, 1)
   (2, 2)
   (3, 4)


So it corresponds to the cost to (i, cost(i)) - to get at i-th station, I have to pay cost(i).

How to find a minimal cost for whole distance with that information?
AnswerRe: Problem with variation of gas station problem. Pin
Karol Nowak16-Apr-18 22:44
Karol Nowak16-Apr-18 22:44 
AnswerRe: Problem with variation of gas station problem. Pin
Daniel Pfeffer17-Apr-18 22:38
professionalDaniel Pfeffer17-Apr-18 22:38 
QuestionProving an algorithm wrong Pin
Member 1377958614-Apr-18 6:39
Member 1377958614-Apr-18 6:39 
AnswerRe: Proving an algorithm wrong Pin
Richard Andrew x6415-Apr-18 6:04
professionalRichard Andrew x6415-Apr-18 6:04 
GeneralRe: Proving an algorithm wrong Pin
Gerry Schmitz15-Apr-18 8:05
mveGerry Schmitz15-Apr-18 8:05 
GeneralRe: Proving an algorithm wrong Pin
Richard Andrew x6415-Apr-18 8:26
professionalRichard Andrew x6415-Apr-18 8:26 
GeneralRe: Proving an algorithm wrong Pin
Richard MacCutchan15-Apr-18 21:30
mveRichard MacCutchan15-Apr-18 21:30 
AnswerRe: Proving an algorithm wrong Pin
Jochen Arndt15-Apr-18 21:45
professionalJochen Arndt15-Apr-18 21:45 
GeneralRe: Proving an algorithm wrong Pin
Richard MacCutchan15-Apr-18 22:27
mveRichard MacCutchan15-Apr-18 22:27 
QuestionCan someone please help me optimize(decrease time complexity) this algorithm.. Pin
Member 137677177-Apr-18 10:37
Member 137677177-Apr-18 10:37 
AnswerRe: Can someone please help me optimize(decrease time complexity) this algorithm.. Pin
Patrice T7-Apr-18 20:15
mvePatrice T7-Apr-18 20:15 
QuestionRe: Can someone please help me optimize(decrease time complexity) this algorithm.. Pin
claymorehack18-May-18 3:38
claymorehack18-May-18 3:38 
AnswerRe: Can someone please help me optimize(decrease time complexity) this algorithm.. Pin
Richard MacCutchan18-May-18 5:59
mveRichard MacCutchan18-May-18 5:59 
QuestionAlgorithm for golf putting. Slope 1-4 degrees Pin
Member 1375000827-Mar-18 11:06
Member 1375000827-Mar-18 11:06 
AnswerRe: Algorithm for golf putting. Slope 1-4 degrees Pin
Gerry Schmitz2-Apr-18 6:01
mveGerry Schmitz2-Apr-18 6:01 
Questionrecursive algorithm Pin
Member 1374335523-Mar-18 7:00
Member 1374335523-Mar-18 7:00 
AnswerRe: recursive algorithm Pin
Gerry Schmitz23-Mar-18 12:00
mveGerry Schmitz23-Mar-18 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.