UVA 12166 Equilibrium Mobile

Source: Internet
Author: User

Just greedy. First think about the final balance, if you know the total weight, then the weight of each node is actually determined.

Each node in the left-to-right actually does not affect, and only the number of layers. Now in turn, if you do not modify a node, then you can calculate the total quality, the total quality of the occurrence of the highest number of times remain unchanged.

/**********************************************************--------------Tyrannosaurus---------* * Author Abyssalfish ***********************************************************/#include<bits/stdc++.h>using namespaceStd;typedefLong Longll;Const intMaxd = -, LEN = (1<< the)* A+Ten;CharS[len];map<ll,int>CNT;//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif    intT scanf"%d",&T);  while(t--) {scanf ("%s", s); Char*p =s; intD =0;        Cnt.clear ();  while(*p) {            if(IsDigit (*p)) {ll x= *p-'0';  while(IsDigit (* (++p))) x = x*Ten+*p-'0'; Cnt[x<<d]++; if(*p = =']') d--; if(!*p) Break; }            Else if(*p = ='[') d++; P++; }        intsum =0, M =0;  for(auto pr:cnt) {sum+=Pr.second; M=Max (M,pr.second); } printf ("%d\n", sum-l); }    return 0;}

UVA 12166 Equilibrium Mobile

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.