2019 CCF Camp day 1

Here the first day said he was very ignorant force. Then find ckw talking about linear data structure is very difficult.

About stacks and queues

1. Use deque

and <int> out;

de.push_back(x);

de.push_front(x);

de.pop()_back;

de.pop()_front;

de.back ();

de.front ();

de.empty();

2. The title sequence on brackets

The title tells us the importance of good && and || consideration.

With a stack storage right parenthesis, the event left parenthesis is popped judgment.

#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;

string s1;
int len,xu;
bool vis[109];
stack < pair<char,int> > q;
char now;

int main(){
    cin>>s1;
    len=s1.size();
    for(int i=0;i<len;i++){
        if(s1[i]=='('||s1[i]=='[')
            q.push(make_pair(s1[i],i));
        else{
            if(!q.empty()){
                now=q.top().first;
                xu=q.top().second;
            }
            if(s1[i]==')'&&now=='('){
                vis[i]=1;vis[xu]=1;q.pop();
            }
            if(s1[i]==']'&&now=='['){
                vis[i]=1;vis[xu]=1;q.pop();
            }
        }
    }
    for(int i=0;i<len;i++){
        if(vis[i]==0){
            if(s1[i]=='('||s1[i]==')'){
                printf("()");
            }
            if(s1[i]=='['||s1[i]==']'){
                printf("[]");
            }
        }
        else printf("%c",s1[i]);
    }
    return 0;
}
View Code

3. monotonous stack

Consider this question: to give you a number, its right to obtain a value for each of the first big digital
To a position equal to its number. Required to achieve linear.
Scan the entire sequence from right to left, not sure of the stack encountered larger than the top of the stack has been popped. Until no longer determined. (Reverse scan for the most hours)

4. a problem

It has an n digital a [1] ... a [n], for all 1 <= L <= R <= n seek
max (a [L], a [L + 1], ..., a [R]) and summed, n <= 1e6.
 
Reverse consider, consider a digital largest maximum range which can become. When the determined left and right is greater than the number of his (the opposite of it again sweep) (considered a [0] and a [n + 1] is positive infinity Laid to avoid arbitration) a pit is equal to the number to meet Imperial left greater than right (for example, 1111111)
5. Another problem
Consider an n digits, seeking 1 <= L <= R <= n such that (R? -L + 1) * min (a [L], a [L + 1], ..., a [R]) Maximum . n <= 1000000
And on a question like, seek out, compare, very violent solution.
6. There is also a problem
There is a matrix, each location is 0 or 1. Seeking the largest all sub-matrix. n * m <= 1000000.
And can be done with the prefix, can scan each line, each line in the upward seeking the minimum reachable. They are (nm) o.
 
Monotonous queue
The title said sliding window, meaning that, than you will be playing badly off than you than you are late.
The problem is that there is a number of {a_n} and m intervals [L (i), R (i)], satisfies L (i) <= L (i + 1), R (i) <= R (i + 1) . Demand interval maximum value for each interval.
Larger than the head of the queue, the queue is emptied reentry team; small directly into the team. o (n)
List
No use.
 Prefix and differential
o (n) pretreatment, o (1) Inquiry
And one-dimensional and two-dimensional prefix and prefix. Uh-D is relatively difficult to understand,
求:b[x,y]=b[x-1,y]+b[x,y-1]-b[x-1,y-1]+a[x,y]
Summing matrix: s (x1, y1, x2, y2) = b [x1-1, y1-1] + b [x2, y2] -b [x1-1, y2] + b [x2, y1-1]
Two-dimensional difference is very magical
In fact, the difference is the prefix and the reverse process, may consist of a prefix and a push over.
Radix Sort
15 th power of 2 = 32768
Radix sort is a barrel row, more generally, it is open to every figure, in accordance with the last one first row, from low to high in turn advance. Or promote from high to low. It can also be converted to a binary barrels row.
STL
 
#include <algorithm>
 
 stack,queue,deque,priority_queue,vector,set,map
deque constant is not small, do not use
priority_queue big heap root, rootlets can be inserted opposite of the stack or operator overloading.
 
vector Do not v.size () -! 1 because it is a type of unsigned int, to empty vector-1 will get an INF
About v.resize () which is a complexity of O (max (1, parameters () in the resize - original size ())) of

v.clear () and the vector <> (). distinction swap (v) a.
• The former is pretending cleared, the actual memory has not been recovered.
• The latter is really recovered, but the needs and v.size () is proportional to the size of the time

 

 

Guess you like

Origin www.cnblogs.com/jindui/p/11272543.html