Into STL

Quick Sort

Quick Sort is a classical algorithm:

#include <algorithm> // header 
Sort (A, A + n); // for a storage index starts from 0, an array of length n in ascending order

 

vector container

vector container. As the number of elements and changing the size. It is actually an array, much stronger than the array.

Let's look at several of its operations:

Vector < int > V; // define 
V.push_back (X); // added at the end of an element X 
V.pop_back (); // end delete an element 
v.size (); // returns the number of elements in the container

It can also be accessed using the subscript. (Starting from 0)

And normal queue, as it has these basic operations: 
v.size (); // returns the number of elements in the q 
V.empty (); // Returns whether q is empty, return null 1, otherwise 0 
V.push (k); // inserted at the end q of k 
; V.pop () // first element is deleted q
 
--- the most important operation 
V.top (); // return the first element q

 

bitset

bitset pressure level to the complexity divided by the basis of the original 32 

#include <bitset> 

bitset <N> S; // This will build up a bitset 

S. SET (); // all become. 1 
S.reset (); // all become 0 

S.count (); // returns the number 1 
S.flip (); // put each bit inverted S 
S.flip (i); // only the first i is negated 

S.any (); // returns whether there 1 
S.none (); // returns 1 if no 

/// said they were not aware of this seemingly regressed operating what is the use 
a.to_ulong () // turn into a number of unsigned long long. 

// bitset support bit arithmetic operation, very strong. 

as A = A & B; A = A ^ B; A = A | B;

 

map

#include <Map> 

Map <type1, type2> A; // . This defines a Map 

. Note that where the subscript represents type1 type, type2 indicates the type of number is stored 

, for example, Map < String , int > A, Map < int , int > A ... 

modified, are used like: A [Type1] = Type2 

a.erase (Type1) // indicates remove a number 
a.clear (); // empty 
a.empty (); // determines whether the air 
a.size (); // returns the number of elements of a

map usage or many.

Note that in general, we define

map <int, int> h;

If you want to assign a certain location, you can directly call

h[x] = y;

But note that, because almost all of us can only use STL containers

:: iterator it;

To get the position, so if we want to find out the corresponding value, then use

it -> first 或 it -> seond

Two operations.

Finally, we need to know to achieve map is similar to the set, so he also supports finding the minimum and maximum log loglog.

Specifically, we can call:

for (map<int,int> :: iterator it = h.begin(); it != h.end(); it ++) {
    printf("%d\n",it->first)
    H[it->first] = 1;
}

 

set

#include < set > set < int > A; // This will build a set of important to note: set that can not support duplicate elements, want to have repeated elements, you can use the multiset 
multiset < int > A; // it can support duplicate elements inserted. 
a.insert (x); // represents a x element inserted inside the set. 
a.erase (x); // represents the set of all there is a number of x deleted. 
a.erase (a.find (x) ); // this indicates that only a delete X 
* a.begin () // represents the minimum value 
* a.end () // indicates a position of the maximum 
* - a.end () // indicates a maximum value // because the return is an iterator, the specific numerical values to be added in front of a number *. 
May sometimes have to use an iterator several times, so we can put him down and stored, it is represented by a, in which it is defined like this:











multiset < int > :: Iterator IT;
 // less like the above minimum value, so may represent = a.begin IT (), the printf ( "% D \ n-", * IT). 

IT ++ can be represented by the following elements of a position, of course, do not abuse, because ++ is the need to log time complexity. . 

Wherein, the two most important SET operation which is inside the above two vector operations, i.e. lower_bound and upper_bound,. 

IT = a.lower_bound (x) // indicates greater than or equal to find a first element iterator x 
it = a. upper_bound (x) // represents a greater than x find the first element of the iterator

 

ctime

+ Random testing time use

At some point - random function can be used to cheat points to use, next time we mention

srand (Time ( 0 )) // random seed, does not have this stuff, random equivalent to no random. 

main point is this: 

int ST = Clock (); 

// do STH 

printf ( " % LF \ the n- " , ( Double ) (Clock () - ST) / CLOCKS_PER_SEC)

Note contains the header files

#include <stdlib.h>
#include <time.h>

 

Guess you like

Origin www.cnblogs.com/lightworkshopnoi/p/11334515.html