主题链接:

HDU:

pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430

ZJU:

problemId=4888" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem.do?

problemId=4888

Problem Description
Today is Yukari's n-th birthday. Ran and Chen hold a celebration party for her. Now comes the most important part, birthday cake! But it's a big challenge for them to place n candles on the top of the cake. As Yukari has lived for such a long long time, though
she herself insists that she is a 17-year-old girl.

To make the birthday cake look more beautiful, Ran and Chen decide to place them like r ≥ 1 concentric circles. They place ki candles equidistantly on the i-th circle, where k ≥ 2, 1 ≤ i ≤ r. And it's optional to place at most one candle at the center
of the cake. In case that there are a lot of different pairs of r and k satisfying these restrictions, they want to minimize r × k. If there is still a tie, minimize r.
 
Input
There are about 10,000 test cases. Process to the end of file.

Each test consists of only an integer 18 ≤ n ≤ 1012.
 
Output
For each test case, output r and k.
 
Sample Input
18
111
1111
 
Sample Output
1 17
2 10
3 10
 
Source

题意:

要在一个蛋糕上放置 n 根蜡烛,摆成 r 个同心圆,每一个同心圆的蜡烛数为 k ^ i ,中间的圆心能够放一根或者不放,使得 r * k 最小,若有多个答案输出 r 最小的那个。

PS:

由于r是非常小的 !

枚举r查找k。

代码例如以下:(HDU,ZOJ上把64位换为long long就OK啦……)

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
//typedef long long LL;
typedef __int64 LL;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
LL n;
LL findd(LL m)
{
LL l, r, mid;
l = 2;
r = n;
while(l <= r)
{
mid = (l+r)/2;
LL sum = 0, tt = 1;
for(LL i = 1; i <= m; i++)
{
if(n/tt < mid)//注意可能溢出用除法推断一下
{
//tt*mid > n
sum = n+1;
break;
}
tt*=mid;
sum += tt;
// if(sum > n)//防止溢出
// break;
}
if(sum == n-1 || sum == n)
{
return mid;
}
if(sum < n-1)
{
l = mid+1;
}
else if(sum > n)
{
r = mid-1;
}
}
return -1;//没有符合的
} int main()
{
LL r, k, rr, kk;
while(~scanf("%I64d",&n))
{
rr = r = 1;
kk = k = n-1;
for(LL i = 2; i <= 64; i++)
{
LL tt = findd(i);
// if(i >= n)
// break;
// printf("tt:%I64d>>>%I64d\n",i,tt);
if(i*tt < rr*kk && tt != -1)
{
r = i;
k = tt;
rr = i;
kk = tt;
}
}
printf("%I64d %I64d\n",r,k);
}
return 0;
} /*
18
111
1111
1022
8190
134217726
34359738366
68719476734
*/

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU 4430 &amp; ZOJ 3665 Yukari&#39;s Birthday(二分法+枚举)的更多相关文章

  1. zoj 3665 Yukari's Birthday(枚举+二分)

    Yukari's Birthday Time Limit: 2 Seconds       Memory Limit: 32768 KB Today is Yukari's n-th birthday ...

  2. HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)

    题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...

  3. HDU 4430 Yukari's Birthday(二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4430 题目大意:给定n个蜡烛,围绕蛋糕的中心插同心圆,从里往外分别是第1圈.第2圈....第r圈,第 ...

  4. hdu 4430 Yukari's Birthday 枚举+二分

    注意会超long long 开i次根号方法,te=(ll)pow(n,1.0/i); Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others) ...

  5. hdu 4430 Yukari's Birthday (简单数学 + 二分)

    Problem - 4430 题意是,给出蜡烛的数量,要求求出r和k,r是蜡烛的层数,k是每一层蜡烛数目的底数. 开始的时候,没有看清题目,其实中间的那根蜡烛是可放可不放的.假设放置中间的那根蜡烛,就 ...

  6. hdu 4430 Yukari's Birthday

    思路: 分析知道1<=r<40:所以可以枚举r,之后再二分k. 代码如下: #include<iostream> #include<stdio.h> #includ ...

  7. HDU 4430 Yukari's Birthday (二分+枚举)

    题意:给定一个n(18 ≤ n ≤ 10^12),一个等比数列k + k^2 + .......+ k^r = n 或者 = n-1,求出最小的k*r,如果最小的不唯一,则取r更小的 分析:两个未知数 ...

  8. HDU 4430 Yukari's Birthday (二分)

    题意:有 n 个蜡烛,让你插到蛋糕上,每一层要插 k^i个根,第0层可插可不插,插的层数是r,让 r * k 尽量小,再让 r 尽量小,求r 和 k. 析:首先先列出方程来,一个是不插的一个是插的,比 ...

  9. HDU - 4430 Yukari's Birthday(二分+枚举)

    题意:已知有n个蜡烛,过生日在蛋糕上摆蜡烛,将蜡烛围成同心圆,每圈个数为ki,蛋糕中心最多可摆一个蜡烛,求圈数r和看,条件为r*k尽可能小的情况下,r尽可能小. 分析:n最大为1012,k最少为2,假 ...

随机推荐

  1. WPF界面设计技巧(2)—自定义漂亮的按钮样式

    原文:WPF界面设计技巧(2)-自定义漂亮的按钮样式 上次做了个很酷的不规则窗体,这次我们来弄点好看的按钮出来,此次将采用纯代码来设计按钮样式,不需要 Microsoft Expression Des ...

  2. JAVA逆向&反混淆-追查Burpsuite的破解原理(转)

    0x00 摘要: 本系列文章通过对BurpLoader的几个版本的逆向分析,分析Burpsuite的破解原理,分析Burpsuite认证体系存在的安全漏洞. 0x01 JD-GUI的用途与缺陷: JD ...

  3. [IOS]UIWebView实现保存页面和读取服务器端json数据

    如何通过viewView保存访问过的页面?和如何获取并解析服务器端发送过来的json数据?通过一个简单的Demo来学习一下吧! 操作步骤: 1.创建SingleViewApplication应用,新建 ...

  4. 泛泰A850 (高通8064+720p)刷4.4专用中文recovery TWRP2.7.1.3版

    欢迎关注泛泰非盈利专业第三方开发团队 VegaDevTeam  (本team 由 syhost suky zhaochengw(z大) xuefy(大星星) tenfar(R大师) loogeo cr ...

  5. Cocos2d-x3.0下一个 Lua与C++打电话给对方

    这里谈下Lua与C++如何实现相互通话 原来的连接:http://blog.csdn.net/qqmcy/article/details/26052771 DJLCData.h 实现类 // // D ...

  6. [改变自己wordpress.2]至wordpress再加上简单的debug sql调试.

    或者说,同事. 需要帮助她打印出来sql 调试输出到页面sql 在这里,我们使用插件或一个的方式来启动配置文件wordpress的debug 在插件文件夹 wordpress/wp-content/p ...

  7. IIS6,IIS7中查看w3wp进程

    当我们服务器创建了很多应用程序池,然后某个w3wp.exe进程占用CPU和内存过高,我们怎么查找这个w3wp.exe进程属于哪一个网站呢.其实微软为我们提供了很好的查看工具: 首先打开windows任 ...

  8. 解决mongodb设备mongod命令不是内部或外部的命令

    1:安装 去mongodb的官网http://www.mongodb.org/downloads下载32bit的包 解压后会出现下面文件 在安装的盘C:下建立mongodb目录,拷贝bin目录到该目录 ...

  9. SharePoint综合Excel数据与Excel Web Access Web部分

    SharePoint综合Excel数据与Excel Web Access Web部分 Excel Web Access Web零件SharePoint于Excel以电子形式提交数据. 1. 打开Exc ...

  10. 【转】求质数算法的N种境界

    原文地址:http://blog.csdn.net/program_think/article/details/7032600/ ★引子 前天,俺在<俺的招聘经验[4]:通过笔试答题能看出啥?& ...