A

来源:互联网 发布:贴吧娘贴吧君分手知乎 编辑:程序博客网 时间:2024/05/29 11:31

You have a single 3D printer, and would like to use it to produce n

statues. However, printing the statues one by one on the 3D printer takes a long time, so it may be more time-efficient to first use the 3D printer to print a new printer. That new printer may then in turn be used to print statues or even more printers. Print jobs take a full day, and every day you can choose for each printer in your possession to have it print a statue, or to have it 3D print a new printer (which becomes available for use the next day).

What is the minimum possible number of days needed to print at least n

statues?
Input

The input contains a single integer n
(1≤n≤10000

), the number of statues you need to print.
Output

Output a single integer, the minimum number of days needed to print at least n

statues.
Sample Input 1
1
Sample Output 1
1

Sample Input 2
5
Sample Output 2
4

这道题想了半天想歪了,以为用啥二分啊我分分分了半天,还是没出来,后来列了从1到17个雕塑要用的时间就灵光一现发现规律了啊啊啊啊,激动地打下了代码,小心地交了上去,侥幸地过了!!!!!!打完这题我就弃赛了哈哈。
思路就是前几天肯定都是成倍成倍地复制打印机啊,最后一天打塑像。就是x=1*2……*2,当x大于等于我们要的雕塑时,就可以开始打印啦。所以就是打印打印机的这么多天加上一天打雕塑的时间。完美!

#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;int main(){    int n,l,x=1;    scanf("%d",&n);     if(n==1){        printf("1\n");        return 0;    }    for(int i=1;i<n;i++){        x=x*2;        if(x>=n){            printf("%d\n",i+1);            return 0;        }    }}
原创粉丝点击