1068 birthday cake

Source: Internet
Author: User
Description

July 17 is the birthday of mr. w, ACM-THU for this to create a volume of N π M-layer birthday cake, each layer is a cylinder. Set the number of I (1 <= I <= m) layers from bottom to top to a column with Ri radius and HI height. When Siri + 1 and HI> Hi + 1. To minimize the cost of using cream on a cake, we hope that the surface of the cake (except the bottom of the bottom layer) has the minimum area Q. To make Q = s π, program the N and M given to find out the cake production scheme (appropriate RI and HI values) and minimize S. (All data except Q is a positive integer)

Input

The test data contains multiple groups of data each with two rows. The first behavior n (n <= 10000) indicates that the volume of the cake to be prepared is N π; the second behavior M (M <= 20) indicates that the number of layers of the cake is M.

Output

Only one row is a positive integer S (if there is no solution, S = 0 ).

Sample Input
1002
Sample output
68
Prompt

Cylindrical formula: Volume V = π r2h, side area a' = 2 π RH, bottom area A = π r2

Source
Noi1999 by aluvin

This question is searched by DFS to ensure that the correct value can be found within the specified time.

 # include 
   
     # define in (a, B) (a 
    
      N | S + mins [level-1]> bests | 2 * (N-V) /R + S> = bests) // If you replace level-1 in the brackets with level, it is 32 msreturn; int I, j, HH; for (I = R-1; i> = level; I --) {If (Level = m) S = I * I; HH = in (n-v-MINV [level-1]) /(I * I), h-1); For (j = HH; j> = level; j --) DFS (V + I * J, S + 2 * I * j, level-1, I, j) ;}} int main () {int I; MINV [0] = 0; mins [0] = 0; for (I = 1; I <= 20; I ++) {MINV [I] = MINV [I-1] + I * I; mins [I] = mins [I-1] + 2 * I;} while (scanf ("% d", & N, & M) = 2) {bests = 0x7fffffff; DFS (0, 0, m, n + 1, n + 1); If (bests = 0x7fffffff) printf ("0 \ n "); elseprintf ("% d \ n", bests) ;}return 0 ;}
    
   

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.