BUG algorithm problem common errors (summary)

1. Fast row partition

if(l >= r)
    return ;
int i = l, j = r;
int tmp = v[i];
while(i < j) {
    while(i < j && v[j] >= tmp) j--;
    while(i < j && v[i] <= tmp) i++;
    if(i < j) swap(v[i], v[j]);
}
swap(v[l], v[i]);

2. pq collation of

and pop is just the opposite of the comparison is

struct cmp{
    bool operator ()(const pair<int,pair<int,int>> &a, const pair<int,pair<int,int>> &b) {
        return a.first > b.first;
    }
};

3. kmp the next array

next[0] = -1;
for(int i=1; i<len; i++) {
    int j = next[i-1];
    while(j != -1 && s[j+1] != s[i])
        j = next[j];
    if(s[j+1] == s[i])
        next[i] = j+1;
    else 
        next[i] = -1;
}

Guess you like

Origin www.cnblogs.com/Draymonder/p/10990569.html