Topic links
Test instructions
In a room with a width of R, there is a weight of s, one end of each balance hanging weights, or hanging another balance, and each balance to maintain balance.
All weights are placed on the balance and the total width does not exceed the maximum width of the room.
Ideas:
Each node can have only two child nodes, which is the form of a binary tree.
By enumerating the patterns of the binary tree and then enumerating the weights placed on each leaf node, the width of each scheme is calculated and the answer is calculated.
For each additional balance, you can put the weight number + 1.
Note
Pit in 0 output, with PRIMTF ("%.9lf\n", 0) output is 0 with 0.0来 output is 0.000000 miserable wa three hair.
Code:
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <ctime>6#include <Set>7#include <map>8#include <list>9#include <stack>Ten#include <queue> One#include <string> A#include <vector> -#include <fstream> -#include <iterator> the#include <iostream> -#include <algorithm> - using namespacestd; - #defineLL Long Long + #defineINF 0x3f3f3f3f - #defineMOD 1000000007 + #defineEPS 1e-5 A #defineMAXN 110 at #defineMAXM 100 - #defineDD {cout<< "Debug" <<ENDL;} - #definePA {System ("pause");} - #defineP (x) {Cout<<x<<endl;} - #definePD (x) {printf ("%.7lf\n", x);} - #defineK (x) {printf ("Case%d:", ++x);} in #defineS (x) {scanf ("%d", &x);} - #defineSD (x) {scanf ("%lf", &x);} to #defineMes (x, D) {memset (x, D, sizeof (x));} + #defineDo (i, X) for (i = 0; i < x; i + +) - #defineDoD (i, X, L) for (i = x; I >= l; I-) the #defineDoe (i, X) for (i = 1; i <= x; i + +) * intN; $ DoubleR, ans;Panax Notoginseng DoubleW[MAXN], V[MAXN]; - DoubleLL[MAXN], RR[MAXN]; the BOOLVIS[MAXN]; + intORDER[MAXN]; A voidRead () the { +scanf"%LF", &R); -scanf"%d", &n); $ for(inti =1; I <= N; i + +) $scanf"%LF", &w[i]); - } - voidGet_ans (intu) the { -memset (LL,0,sizeof(ll));Wuyimemset (RR,0,sizeof(RR)); thememset (V,0,sizeof(v)); - Wu for(inti = u; i >0; I--) - { About if(Order[i] = =-1) $ { - intx = i *2; - inty = i *2+1; -V[i] = V[x] +V[y]; A DoubleLi = v[y]/V[i]; + DoubleRI = v[x]/V[i]; the -Ll[i] = min (-li + ll[x], RI +ll[y]); $Rr[i] = max (-li + rr[x], RI +rr[y]); the } the Else if(Order[i]) the { theV[i] =W[order[i]]; - } in } the the Doubletemp = rr[1]-ll[1]; About //printf ("%.9lf\n", temp); the if(Temp-r < EPS && temp >ans) theAns =temp; the } + - voidDfsintUintNumintcount) the {Bayi //printf ("%d%d%d\n", u, num, count); the if(Count = =0) the { -Get_ans (U-1); - return ; the } the Else if(Order[u/2] != -1) the { theDFS (U +1, NUM, count); - } the Else the { the if(Count >num)94 { theOrder[u] =-1; theDFS (U +1, Num +1, count); theOrder[u] =0;98 } About - if(num = =1&& Count >1)101 return ;102 for(inti =1; I <= N; i + +)103 if(!Vis[i])104 { theVis[i] =true;106Order[u] =i;107DFS (U +1, Num-1, Count-1);108Order[u] =0;109Vis[i] =false; the }111 } the }113 voidSolve () the { thememset (Vis,false,sizeof(Vis)); thememset (Order,0,sizeof(order));117Ans =-1;118 if(n = =1) printf ("%.10lf\n",0.0);119 Else - {121order[1] = -1;122Dfs2,2, n);123printf (ans = =-1?"-1\n":"%.10lf\n", ans);124 } the }126 127 intMain () - {129 intT; thescanf"%d", &T);131 while(T--) the {133 read ();134 solve ();135 }136 return 0;137}View Code
Uva 1354 Mobile Computing