HDU 2648 Shopping

Source: Internet
Author: User

Original title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2648

The method of pure violence t_t ...

As follows:

1#include <cstdio>2#include <cstdlib>3#include <string>4#include <iostream>5#include <algorithm>6typedefCharstate[ *];7 Char*target ="Memory";8 Const intMax_n =11000;9 structnode{Ten State name; One     intV, S; ANode *ch[2]; -Inlinevoid -     Set(int_v =0,Char*SRC ="",int_s =0, Node *p =NULL) { thech[0] = ch[1] =p; -v = _v, s =_s, strcpy (name, SRC); -     } -Inlinevoidpush_up () { +s = ch[0]->s + ch[1]->s +1; -     } +InlineintcmpChar*SRC)Const{ A         if(0= = strcmp (src, name))return-1; at         Else if(-1= = strcmp (src, name))return 0; -         return 1; -     } - }; - structsizebalancetree{ -Node *tail, *NULL, *Root; in Node Stack[max_n]; -     voidinit () { toTail = &stack[0]; +         NULL= tail++; -         NULL-Set(); theRoot =NULL; *     } $Inline Node *newnode (Char*name,intv) {Panax NotoginsengNode *p = tail++; -P->Set(V, Name,1,NULL); the         returnp; +     } AInlinevoidRotate (node* &x,intd) { theNode *k = x->ch[!d]; +X-&GT;CH[!D] = k->Ch[d]; -K-&GT;CH[D] =x; $K->s = x->s; $X->push_up (); -x =K; -     } theInlinevoidMaintain (node* &x,intd) { -         if(X->ch[d] = =NULL)return;Wuyi         if(X->ch[d]->ch[d]->s > x->ch[!d]->s) { theRotate (x,!d); -}Else if(X->ch[d]->ch[!d]->s > x->ch[!d]->s) { WuRotate (x->ch[d], D), rotate (x,!d); -}Else { About             return; $         } -Maintain (x,0), Maintain (x,1); -     } -InlinevoidInsert (node* &x,Char*name,intv) { A         if(x = =NULL){ +x =NewNode (name, v); the             return; -}Else { $x->s++; the             intD = x->CMP (name); theInsert (x->Ch[d], name, v); theX->push_up (); the Maintain (x, d); -         } in     } theInline node *modify (node *x,Char*name) { the         if(x = =NULL)return NULL; About         intD = x->CMP (name); the         if(-1= = d)returnx; the         Else returnModify (x->Ch[d], name); the     } +InlinevoidInsertChar*STR,intv =0){ - Insert (root, str, v); the         return;Bayi     } theInlinevoidModify (Char*STR,intv) { thenode* ret =Modify (root, str); -Ret->v + =v; -     } theInlinevoidDFS (Node *x,intVint&ans) { the         if(X! =NULL){ theDFS (x->ch[0], V, ans); the             if(X->v > V) ans++; -DFS (x->ch[1], V, ans); the         } the     } theInlinevoidquery () {94         intCNT =0, ans =0; the         intv = Modify (root, Target)v; the Dfs (Root, V, ans); theprintf"%d\n", ans +1);98     } About }SBT; - intMain () {101 #ifdef LOCAL102Freopen ("In.txt","R", stdin);103Freopen ("OUT.txt","w+", stdout);104 #endif the     Charbuf[ -];106     intN, M, Val;107      while(~SCANF ("%d", &N)) {108 sbt.init ();109          for(inti =0; I < n; i++){ thescanf"%s", buf);111 Sbt.insert (BUF); the         }113scanf"%d", &m); the          while(m--){ the              for(inti =0; I < n; i++){ thescanf"%d%s", &Val, buf);117 SBT. Modify (Buf, Val);118             }119 sbt.query (); -         }121     }122     return 0;123}
View Code

HDU 2648 Shopping

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.