1441: example [2] birthday cake

1441: example [2] birthday cake

 

 answer

The title says \boldsymbol{\mathbf{}\mathbf{R_{i}>R_{i+1}}}radius, too high, \mathbf{H_{i}>H_{i+1}},

That is the radius of the smallest cake layer M is M, M is the smallest high (at this time and the minimum radius of the first layer cakes are high assurance layer M 1)

. 1 . For ( int I = m; I * I * m <= n-; I ++ )
     // I represents the radius of 
 
2 . For ( int J = m; I * I * J <= n-; J ++ )
     / / J represents the high range 
 
3 . IF (i * i + 2 * i * J < Minn)
     // this step is only represented us in the enumeration to the surface area is less than we had previously recorded can continue (to optimize pruning) 
 
. 4 .dfs ( 1 , i * i * j, * I + I 2 * I * J, I, J)
     // into the recursive function 
/ * 
1. start previous one layer 
2. The volume of i * i * j 
3. The surface area of I * J * 2 
4.i denotes a radius 
5.j represents a high 
* /

 

minn represents a minimum surface area so far 

explain DFS 
void DFS ( int d, int v, int s, int R & lt, int H)
 // enumerated d layer, the front layer volume as d v, surface area s, the d layer of radius r, height h 

pruning: 
( 1 ) If (d == m) enumerated enough layers have been described, and if (V == n-), record the surface area of the case, the answer 
( 2 ) if the remaining m- v plus the maximum volume of the cake layer d n can not reach it, discarding 
     due subject of the request and the radius of the cake are decremented high 
     so the maximum radius of the remaining layers of cake R & lt - . 1 , a high maximum H- . 1 , left M- D layer 

( 3 ) If v plus the remaining M- D layer cake volume further than the minimum value of n is then discarded 
     since the subject of the request and high radius cake are decremented 
     so the rest of the cake the minimum radius of layers 1High minimum 1 , remaining M- layer d 
     the minimum, then the radius of the uppermost layer, is a constant high 
( 4 ) optimize the pruning 
     front layer d cake volume V = R & lt [ 1 ] R & lt * [ 1 ] * H [ . 1 ] + ... + R & lt [D] R & lt * [D] * H [D] <R & lt * R & lt [ . 1 ] * H [ . 1 ] + ... + R & lt * R & lt [D] * H [D ] 
     (where r is the radius of the bottom of the cake) 
     
     apparently n- -v <r * r [ . 1 ] * H [ . 1 ] + ... + r * r [D] * H [D] 
     both sides simultaneously / r * 2  
     then left 2 * (NV) / R & lt 
     right is the 2 * R & lt [ . 1 ] * H [ . 1 ] + ... + 2 * R & lt [D] *h [d], that is, before the recording layer of the front surface area minn d 
     is to ensure that S + 2 * (NV) / R & lt < minn, have better solution
     
   

By pruning, and constantly search continues down one

 

 

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<functional>

using namespace std;

int n,m,minn=2e9+1;

void dfs(int d,int v,int s,int r,int h)
{
    if(d==m) 
    {
        if(v==n)
         minn=s;
         return ;
    } 
    if(v+(r-1)*(r-1)*(h-1)*(m-d)<n)  return;  
    if(v+m-d>n) return;
    if(2*(n-v)/r+s>=minn) return;
    
    for(int i=r-1;i>=m-d;i--)
        for(int j=h-1;j>=m-d;j--)
        if((v+i*i*j<=n)&&(s+2*i*j<minn))
        dfs(d+1,v+i*i*j,s+2*i*j,i,j);
    
       
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=m;i*i*m<=n;i++)
      for(int j=m;i*i*j<=n;j++)
      if(i*i+2*i*j<minn)
      dfs(1,i*i*j,i*i+2*i*j,i,j);
      
    printf("%d",minn);
}

 

 

 

 


 

Thank the gods

 

Guess you like

Origin www.cnblogs.com/xiaoyezi-wink/p/10992492.html