• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

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 }
posted @ 2012-10-16 23:46  Hug_Sea  阅读(213)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3