HDU 4430 & ZOJ 3665 Yukari's Birthday(二分法+枚举)
主题链接:
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
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.
Each test consists of only an integer 18 ≤ n ≤ 1012.
18
111
1111
1 17
2 10
3 10
题意:
要在一个蛋糕上放置 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 & ZOJ 3665 Yukari's Birthday(二分法+枚举)的更多相关文章
- zoj 3665 Yukari's Birthday(枚举+二分)
Yukari's Birthday Time Limit: 2 Seconds Memory Limit: 32768 KB Today is Yukari's n-th birthday ...
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
- HDU 4430 Yukari's Birthday(二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4430 题目大意:给定n个蜡烛,围绕蛋糕的中心插同心圆,从里往外分别是第1圈.第2圈....第r圈,第 ...
- 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) ...
- hdu 4430 Yukari's Birthday (简单数学 + 二分)
Problem - 4430 题意是,给出蜡烛的数量,要求求出r和k,r是蜡烛的层数,k是每一层蜡烛数目的底数. 开始的时候,没有看清题目,其实中间的那根蜡烛是可放可不放的.假设放置中间的那根蜡烛,就 ...
- hdu 4430 Yukari's Birthday
思路: 分析知道1<=r<40:所以可以枚举r,之后再二分k. 代码如下: #include<iostream> #include<stdio.h> #includ ...
- HDU 4430 Yukari's Birthday (二分+枚举)
题意:给定一个n(18 ≤ n ≤ 10^12),一个等比数列k + k^2 + .......+ k^r = n 或者 = n-1,求出最小的k*r,如果最小的不唯一,则取r更小的 分析:两个未知数 ...
- HDU 4430 Yukari's Birthday (二分)
题意:有 n 个蜡烛,让你插到蛋糕上,每一层要插 k^i个根,第0层可插可不插,插的层数是r,让 r * k 尽量小,再让 r 尽量小,求r 和 k. 析:首先先列出方程来,一个是不插的一个是插的,比 ...
- HDU - 4430 Yukari's Birthday(二分+枚举)
题意:已知有n个蜡烛,过生日在蛋糕上摆蜡烛,将蜡烛围成同心圆,每圈个数为ki,蛋糕中心最多可摆一个蜡烛,求圈数r和看,条件为r*k尽可能小的情况下,r尽可能小. 分析:n最大为1012,k最少为2,假 ...
随机推荐
- Uva10290 - {Sum+=i++} to Reach N
Problem H {sum+=i++} to Reach N Input: standard input Output: standard output Memory Limit: 32 MB A ...
- cowboy rest
REST Flowcharts 这章节将通过一些列不同的流程图来介绍REST处理状态机. 一个请求主要有四条路线,一个是方法OPTIONS. 一个是方法GET和HEAD.一个是PUT.POST和PAT ...
- 收藏的Android很好用的组件或者框架。
收藏的Android很好用的组件或者框架. android框架 先说两个站点: http://www.androidviews.net/ 非常好的国外开源码站,就是訪问速度有点慢啊 http://w ...
- Qt--将Qt 动态链接生成的exe及依赖dll打包方法
Qt静态编译链接生成的exe文件,不需依赖dll,可以独立运行,发布很方便. 但绝大多数用的都是Qt开源版本,如果用静态链接,会有些限制. 方法之一,就是用动态编译,然后把exe和需要的dll整合成一 ...
- HTML5----响应式(自适应)网页设计
第一步:在网页代码的头部,加入一行viewport元标签 <meta name="viewport" content="width=device-width, in ...
- jconsole线程面板中的阻塞总数和等待总数(转)
阻塞总数 Blocked count is the total number of times that the thread blocked to enter or reenter a monito ...
- Win 10开门人类智慧的世界领先
3月18日,从微软硬件project大会(WinHEC 2015)上传来好消息:今年夏天,Win 10将要正式公布.Win 10公布,有何新意? 微软新领导人纳德拉(Nadella)主张:运计算,大数 ...
- 欢迎CSDN-markdown编辑
CSDN-发布markdown编辑,果断地赞啊!. $(function () { $('pre.prettyprint code').each(function () { var lines = $ ...
- BST树,B树、B-树、B+树、B*树
BST树,B树.B-树.B+树.B*树 二叉搜索树(BST): 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树 ...
- NYOJ129 决策树 【并检查集合】
树的判定 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描写叙述 A tree is a well-known data structure that is either e ...