UVa 1354 Enumeration Subset Mobile Computing

Source: Internet
Author: User

We can calculate the distance between the left and right two suspension points to the root suspension point as long as we enumerate the set of the two sub balance weights.

But in the question asked to find the widest possible balance but not more than the width of the room, unexpectedly how to record the results.

Referring to someone else's code, a vector of a struct is used to save the longest distance between the left and right sides of each set's legal scheme.

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <vector>5#include <map>6#include <cmath>7 #defineMP Make_pair8 #defineFt First9 #defineSd SecondTen using namespacestd; One  Atypedef pair<Double,Double>PDD; -  - Const intMAXN =Ten; the Const intMaxs = +; -  -Vector<pdd>TREE[MAXS]; -  + intN; - DoubleR; + DoubleA[MAXN], w[maxs]; A BOOLVIS[MAXS]; at  - intBitcount (intx) - { -     intAns =0; -      while(x) {ans + = (x &1); X >>=1; } -     returnans; in } -  to voidDfsintS) + { -     if(Vis[s])return ; theVis[s] =true; *     if(Bitcount (S) = =1) {Tree[s].push_back (MP (0,0));return ; } $ Panax NotoginsengPDD t = MP (0,0); -      for(intS1 = (S-1) &S; S1; S1 = (s1-1) &S) the     { +         intS2 = S ^S1; A DFS (S1); Dfs (S2); the         DoubleX1 = w[s2]/w[s], x2 = w[s1]/W[s]; +          for(inti =0; I < tree[s1].size (); i++) -              for(intj =0; J < Tree[s2].size (); J + +) $             { $t.ft = max (x1 + tree[s1][i]. Ft, Tree[s2][j]. Ft-x2); -T.SD = max (x2 + tree[s2][j]. Sd, Tree[s1][i]. Sd-x1); -                 if(t.ft + t.sd <r) tree[s].push_back (t); the             } -     }Wuyi } the  - intMain () Wu { -     intT scanf"%d", &T); About      while(t--) $     { -scanf"%lf%d", &r, &n); -          for(inti =0; I < n; i++) scanf ("%LF", A +i); -         intAll = (1<< N)-1; A  +          for(inti =0; I <= all; i++) the         { -W[i] =0; $ tree[i].clear (); the              for(intj =0; J < N; J + +)if(I & (1<<j)) theW[i] + =A[j]; the         } the  -memset (Vis,false,sizeof(Vis)); in DFS (all); the         DoubleAns =-1; the          for(inti =0; I < tree[all].size (); i++) ans = max (ans, tree[all][i]. Ft +Tree[all][i]. SD); About         if(Ans <0) puts ("-1"); the         Elseprintf"%.9f\n", ans); the     } the  +     return 0; -}
code June

UVa 1354 Enumeration Subset Mobile Computing

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.