ObjectiveThe method of LCA has multiple and diverse, summed up is the following 4 kinds. I hope you can refuel!The violence to seek LCAWe consider DFS to find each point of the father (under the current root), and then directly first violent jump to the same depth, and then jumpvoid dfs(int u,int f){ fa[u]=f;dep[u]=dep[f]+1; for(re int i=front[u];i;i=e[i].nxt){ int v=e[i].to; if(v==f)continue; dfs(v,u); }}int lca(int u,in
Main topic:Gives a string a, which requires the shortest string b,b not a subsequence. Find the shortest length and shortest number of strings | a|Exercises1. The game did not come out, after one months to see the problem, although retired, or determined to understand it.2. Basically, the network is directly affixed to the code. I'll write the solution briefly:We can imagine moving on string a. At the beginning of a starting node (node No. 0), if we select the character P, now on the K node, the
how to delete an item from a hash table. To delete a node from a linked list, first locate the node's parent node, and then use the next pointer of the parent node to delete and splice the node. The implementation of memcached is similar to the following:
Void assoc_delete (const char * key, const size_t nkey, const uint32_t hv) {item ** before = _ hashitem_before (key, nkey, hv ); // obtain the h_next Member Address of the precursor node if (* before) {// find the successful item *
After understanding the trie tree, we can implement 1A. In fact, it is estimated that this question can be used as a result, and advanced data may not be required.
First paste the Code Template of Jilin University
/* ===================================================== =============== * | Trie tree (K cross) | init: Init (); | Note: If tree [I] [TK]> 0 indicates that a word exists, you can also give it more meanings; \ * =================================================== ============= */const
Here's a look at a few searches today
Dfs--depth First Search
Bfs--breadth First Search
A *
Iterative First Search
Today the implementation of DFS and BFS is not detailedWe first look directly at the implementation of a * algorithm (Python-style ...) With a little pseudo-code)1 defA_star_search2Q =Priorityqueue ()3 #priority queue, by the way, the role of the Open table4 q.put (Qnode)5Came_from = {}6 #Came_from as a linked list for the record expan
contains integers (). Their meanings is described above. It's guaranteed the sum of all test cases would not exceed . OutputFor each test case output one line containing one integer, indicating the maximum possible score Baobao can get.Sample Input46) ()) () 1 3 5-1 3 26) ()) () 1 3 5-100 3 23 ()) 1-1-13 ())-1-1-1Sample Output242102HintFor the first sample test case, the optimal strategy are to select in order.For the second sample test case, the optimal strategy are to select in order.is a dp
table. The general practice of removing a node from a linked list is to first locate the node's predecessor, and then use the next pointer of the predecessor node for the deletion and stitching operations. The memcached approach is similar, implemented as follows: void Assoc_delete (const char *key, const size_t nkey, const uint32_t HV) {Item **before = _hashitem_before (key, Nkey, HV);//Get the H_next member address of the precursor node if (*before) {//Find successful item *
: "'silious' is the starting point of all art and aesthetic life. Here, the source of philosophical and aesthetic life is the same ." ("Aesthetic walk") This section describes the aesthetic color of the Study of meditation in Buddhism. There are indeed many similarities between the pure and quiet in artistic creations and the "holy heart and virtual static" in the Buddhist theories. The thinking of the Buddhist family "quiet and dynamic" contains the
-source to super-sink to run the minimum cost maximum flow, two cost add is the answer.As for the idea of the subject itself, similar to bzoj1927 star Racing, put a very conscientious solution below.Heaven knows is the one who is unbeatable1#include 2#include 3#include 4#include 5#include 6 using namespacestd;7 Const intdian=305;8 Const intbian=100005;9 Const intinf=0x3f3f3f3f;Ten intH[dian],nxt[bian],ver[bian],val[bian],cos[bian]; One intD[dian],v[di
Title DescriptionTransmission DoorExercisesFor each product, S->i,ci,infFor employees J can produce products I,i->j,inf,ciFor each employee I and the enumeration to SI=J,I->T,T[I][J]-T[I][J-1],W[I][J]Code#include #include #include #include using namespace STD;#define LL Long LongConst intmax_n= -;Const intmax_n=max_n*Ten+2;Const intmax_m=max_n* -;Const intmax_e=max_m*2;ConstLL inf=1e18; LL M,n,sum,n,mincost; LL A[max_n][max_n],s[max_n],ss[max_n],c[max_n],t[max_n][max_n],w[max_n][max_n]; LL Tot,p
Give a graph and S, T, each time delete an edge, ask each deletion after the s to t the shortest path is changed. Asked to be independent of each other. The shortest road network is built from S, t respectively, and then cut on the shortest road network. If the side of the inquiry is on the shortest road network and the cutting edge changes, it will not change. #include #include#include#includestring.h>#includeusing namespacestd;#defineSZ 456789intN;namespacespfa{intm=0, Vb[sz],dst[sz],fst[sz],
Here is the basic knowledge of Tarjan,Cutting points and cutting edgesFirst to seek the cutting edge,#include #include#includeusing namespaceStd;typedefLong Longll;typedef unsignedLong Longull;#defineLS (t#defineRS ((t#defineMid ((l+r) >>1)#defineMk Make_pair#definePB Push_back#defineFi first#defineSe Second#defineMAXN 100001structEdge {intV,NXT;} E[MAXN*2];intHEAD[MAXN];BOOLqiao[maxn*2];intDFN[MAXN],LOW[MAXN];intN,m,cnt,num;voidAddintXinty) {e[++cnt]
Test instructions: Given an adjacency matrix, that is, a forward graph (with a loop), the minimum coverage path is a few, to find out the traversal order;Idea: The competition chart exists in Hamilton Road, must be able to find a way to traverse all points.#include #include#includeusing namespacestd;intmm[1005][1005];Charch[1005];intnxt[50010];intn,m;intMain () {inti,j,k,head,temp; while(SCANF ("%d", n)! =EOF) {GetChar (); for(i=0; i) {gets (ch); Temp=0; for(j=0; j) {Mm[i][j]=ch[temp]-
Because the knight who hates each other cannot be adjacent, the knight can be connected to the non-side, the meeting request is odd, the problem is to seek no more than the number of nodes on a simple odd circle.Tarjan directly set previously written, the result is wrong, to pay special attention to the side to join the stack of time ... I don't understand the algorithm.#include using namespacestd;#defineBug (x) coutConst intMAXV = ++5;Const intMaxe = MAXV*MAXV;//Open Smallintdfn[maxv],low[maxv]
BUG: Today I wrote a very SB code, the problem actually I have noticed, in the previous writing such code, I also left a mind, but may be a long time not to write these things lead to new problems arising. In fact, I have written a note about this problem before, and now write a deeper impression. The code is first attached:
#ifndef LIST_INSERTREMOVEPRINT_H
#define LIST_INSERTREMOVEPRINT_H
#include
struct ListNode{
int val;
struct ListNode *
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.