Portal 1 (UVa): https://uva.onlinejudge.org/external/13/1354.pdf
Portal 2 (GOJ): http://acm.gdufe.edu.cn/Problem/read/id/1320
Test instructions: Length limit R (1 < R < 10), give N (1 <= n <= 6) Weights, balance (considering weight and arm) balances, to find the maximum length of the balance.
2015 Person Trials # 1004
The game is completely do not know how to do, two days after the game to re-see a bit of the idea is to knock out (weak slag ...) =_=
Followed the code of Wenjun brother.
Caodan is the most recent write multiple for loop at the time always write the wrong variable in the innermost ... I've been looking for a couple of days. What's the matter with me?
Binary enumeration, similar to a line tree from the bottom layer of a layer of processing
#include <bits/stdc++.h>using namespacestd;structtree{DoubleL, R; Tree (DoubleLL =0.0,DoubleRR =0.0): L (LL), R (RR) {}};Const intMAXN =6;intN;BOOLvis[1<<MAXN];//whether the subset has been accessedDoubleR, W[maxn], sum[1<<Maxn];vector<Tree> tree[1<<MAXN];//the solution of preserving subsets conforming to test instructions//calculates the number of weights that the subset contains, which is equivalent to reaching two fork tree nodes when it is 1 .intCountintx) { intAns =0; for(inti =0; I < n; ++i)if(X & (1<<i)) + +ans; returnans;}voidDfsintsubset) { if(Vis[subset])return ; Vis[subset]=true; if(count (subset) = =1{tree[subset].push_back ()) {tree ()); return; } //enumerates all the subsets of the collection for(intleft = (subset-1) & subset; Left left = (left-1) &subset) { intright = subset ^Left ; //according to the formula, the length of the stress arm of the current set DoubleLeftlen = Sum[right]/Sum[subset]; DoubleRightlen = Sum[left]/Sum[subset]; DFS (left); DFS (right); for(inti =0; I < tree[left].size (); ++i) { for(intj =0; J < Tree[right].size (); ++j) { DoubleLL = max (tree[left][i].l + Leftlen, TREE[RIGHT][J].L-Rightlen); Doublerr = max (TREE[RIGHT][J].R + Rightlen, TREE[LEFT][I].R-Leftlen); if(LL + RR <r) Tree[subset].push_back (tree (ll, RR)); } } }}intMain () {intT; scanf ("%d", &t); while(t--) {scanf ("%lf%d", &r, &N); for(inti =0; I < n; ++i) scanf ("%LF", &W[i]); for(inti =0; I < (1<<N); ++i) {Sum[i]=0; Tree[i].clear (); for(intj =0; J < N; ++j) { if(I & (1<<J)) Sum[i] + = w[j];//Binary enumerates the weights of each subset and } } intRoot = (1<<n)-1;//the entire balancememset (Vis,false,sizeof(VIS)); DFS (root); DoubleAns =-1; for(inti =0; I < tree[root].size (); ++i) ans= Max (ans, tree[root][i].l +TREE[ROOT][I].R); if(ans = =-1) printf ("-1\n"); Elseprintf"%.15lf\n", ans); } return 0;}
UVa 1354 Mobile Computing | GOJ 1320 non-modified balance problem