It is not difficult to find that every one hours, in addition to the bottom right of the balloon is all blue, the others and one hours of the balloon is the same, so it can be recursive. Then define a similar prefix and something F (k,i) indicates the number of red balloons above I line after k hours. The total number of red balloons in the K-Hour is preprocessed by C (k), and the termination condition is observed recursively.
#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;Const intMAXN = to; ll C[maxn];ll F (intKinti) { if(!i)return 0; if(i = = (1<<K))returnC[k]; inttot =1<< (K-1); if(I>tot)returnF (K-1, I-tot) + (c[k-1]<<1); Else returnF (K-1, i) <<1;}intMain () {intT scanf"%d",&T); c[0] =1; for(inti =1; i < MAXN; i++) C[i] = c[i-1]*3; intKas =0; while(t--){ intK,a,b; scanf"%d%d%d",&k,&a,&b); ll ans= f (k,b)-F (k,a-1); printf ("Case %d:%lld\n",++Kas,ans); }}
UVA 12673 erratic Expansion strange balloon swell