ZOJ-3665 Yukari's Birthday

题意:给出生日n,向多层蛋糕插蜡烛,每层插k^i(i=1,2,3....),求r层蛋糕使k*r最小,若多组k*r相同取r最小的,最上面一层可以选择插1根蜡烛。

思路:枚举+二分

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3665

 

View Code
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <string>
 7 using namespace std;
 8 #define LL long long
 9 #define inf 1000000000000
10 
11 LL num[10005][70];
12 LL n,R,K;
13 
14 void Init(){
15     for(LL i=1;i<=10000;i++){
16         LL p=i;
17         for(LL j=1;j<=64;j++){
18             num[i][j]=num[i][j-1]+p;
19             p*=i;
20             if(p>1000000000000LL) break;
21         }
22     }
23 }
24 
25 int main(){
26 
27 //    freopen("data.in","r",stdin);
28 //    freopen("data.out","w",stdout);
29 
30     Init();
31     while(scanf("%lld",&n)!=EOF){
32         LL l=1,r=10000,i;
33         LL sq=sqrt(n);
34         R=1; K=n-1;
35         if(sq*(1+sq)==n||sq*(1+sq)==n-1){R=2; K=sq;}
36         for(i=3;i<=64;i++){
37             LL l=2,r=10000;
38             while(l<=r){
39                 LL mid=(l+r)>>1;
40                 if(num[mid][i]==n||num[mid][i]==n-1){
41                     R=i;
42                     K=mid;
43                 }
44                 if(num[mid][i]>n||num[mid][i]==0) r=mid-1;
45                 else l=mid+1;
46             }
47         }
48         printf("%lld %lld\n",R,K);
49     }
50     return 0;
51 }

转载于:https://www.cnblogs.com/Hug-Sea/articles/2726989.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值