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

Algorithms

 
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 
AnswerRe: Problem with variation of gas station problem. Pin
Karol Nowak16-Apr-18 22:44
Karol Nowak16-Apr-18 22:44 
I found a way:

#include <vector>
#include <algorithm>
#include <deque>
#include <stdio.h>

// if jesli starczy paliwa na cala trase
typedef unsigned long long int ulli;

using namespace std;

void sliding_window_minimum(vector<pair<ulli, ulli>> st, ulli n, ulli targetDist, ulli range)
{
    deque<pair<ulli, ulli>> minimize;
    ulli j = 0;
    for (ulli i = 0; i < n; i++)
    {
        if (st[i].first <= range)
        {
            while (!(minimize.empty()) && (minimize.back().second > st[i].second))
            {
                minimize.pop_back();
            }
            minimize.push_back(st[i]);
            j++;
        }
        else
        {
            break;
        }
    }
    for (ulli k = j; k < n; k++)
    {
        while (!(minimize.empty()) && ((st[k].first - minimize.front().first) > range))
        {
            minimize.pop_front();
        }
        if (minimize.empty()) {
            break;
        }
        ulli tempCost = st[k].second + minimize.front().second;
        while (!(minimize.empty()) && (minimize.back().second > tempCost))
        {
            minimize.pop_back();
        }
        minimize.push_back(make_pair(st[k].first, tempCost));
    }
    while (!(minimize.empty()) && ((targetDist - minimize.front().first) > range))
    {
        minimize.pop_front();
    }
    if (minimize.empty())
    {
        printf("NIE\n");
    }
    else
    {
        printf("%llu", minimize.front().second);
    }
}

int main()
{
    ulli n, d, b;
    scanf("%llu %llu %llu", &n, &d, &b);
    if (b >= d)
    {
        printf("%d", 0);
        return 0;
    }
    int temp = n;
    ulli d1, c1;
    vector<pair<ulli, ulli>> st;
    st.reserve(n+1);
    while (temp--)
    {
        scanf("%llu %llu", &d1, &c1);
        st.push_back(make_pair(d1, c1));
    }
    sliding_window_minimum(st, n, d, b);
}

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 
AnswerRe: recursive algorithm Pin
Peter_in_278023-Mar-18 14:53
professionalPeter_in_278023-Mar-18 14:53 

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.