hdu4430 枚举+二分
Yukari's Birthday
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4934 Accepted Submission(s): 1163
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.
111
1111
2 10
3 10
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef __int64 ll;
ll n;
int main()
{
while(scanf("%I64d",&n)!=EOF)
{
ll r=,k=n-;
int i,j;
for(i=;i<=;i++)
{
ll kl=,kr=n;
while(kl<=kr)
{
ll sum=;
ll mid=(kl+kr)>>;
ll sum_now=;
for( j=;j<=i;j++)
{
if(sum>n)
{
sum=n+;
break;
}
if(n/sum_now<mid)
{
sum=n+;
break;
}
sum_now*=mid;
sum+=sum_now;
}
if(sum==n||sum==n-)
{
if(mid*i<k*r)
{
k=mid,r=i;
}
else if(mid*i==k*r&&i<r)
{
k=mid,r=i;
}
break;
}
if(sum>n||sum<) kr=mid-;
else kl=mid+;
}
}
printf("%I64d %I64d\n",r,k);
}
}
hdu4430 枚举+二分的更多相关文章
- HDU4430 Yukari's Birthday(枚举+二分)
Yukari's Birthday HDU4430 就是枚举+二分: 注意处理怎样判断溢出...(因为题目只要10^12) 先前还以为要用到快速幂和等比数列的快速求和(但肯定会超__int64) 而 ...
- CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。
1514: Packs Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 61 Solved: 4[Submit][Status][Web Board] ...
- 4 Values whose Sum is 0(枚举+二分)
The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...
- hdu4430之枚举+二分
Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...
- HDU 4282 A very hard mathematic problem --枚举+二分(或不加)
题意:问方程X^Z + Y^Z + XYZ = K (X<Y,Z>1)有多少个正整数解 (K<2^31) 解法:看K不大,而且不难看出 Z<=30, X<=sqrt(K) ...
- Subset---poj3977(折半枚举+二分查找)
题目链接:http://poj.org/problem?id=3977 给你n个数,找到一个子集,使得这个子集的和的绝对值是最小的,如果有多种情况,输出子集个数最少的: n<=35,|a[i]| ...
- hdu 5288 OO’s Sequence 枚举+二分
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
- codeforces 613B B. Skills(枚举+二分+贪心)
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
随机推荐
- Unity3d在安卓android的更新(APK覆盖)
其实这并没什么技术难点,也不是完美的热更新方案,只能说是退而求其次的一个方法. 起因主要是因为公司几个U3D项目在立项之初都没有能做好热更新的规化,导致现在要去做U3D的热更新非常难,并且项目已处于中 ...
- 推荐一个PHP扩展 来真正实现PHP多线程的开发
PHP扩展下载:https://github.com/krakjoe/pthreadsPHP手册文档:http://php.net/manual/zh/book.pthreads.php <?p ...
- StateListDrawable 资源
StateListDrawable 用于组织多个 Drawable 对象.当使用 StateListDrawable 作为目标组件 的背景.前景图片时,StateListDrawable 对象所显示的 ...
- 14.1.2 InnoDB表最佳实践:
14.1.2 Best Practices for InnoDB Tables InnoDB表最佳实践: 这个章节描述使用InnoDB表最佳实践: 1.指定一个主键用于每个表使用最多查询的列或者多列, ...
- 【HDOJ】2809 God of War
状态DP. /* 2809 */ #include <iostream> #include <queue> #include <cstdio> #include & ...
- treap启发式合并
注意输入v要在建根的前面. #include <cstdio> #include <iostream> #include <algorithm> #include ...
- 关于echo `git branch | grep \*`
本来想返回一个git当前的分支.但会将这个文件夹下的所有目录与分支一起输出. 原因是 echo `git branch | grep \*` 等价于 echo * master , 而 e ...
- casperjs配合phantomjs实现自动登录百度,模拟点击等等操作 - 怕虎在线www.ipahoo.com图文教程 - 怕虎在线
微信支付取消2万元保证金门槛,这是全民电商来袭!-观点-虎嗅网 微信支付取消2万元保证金门槛,这是全民电商来袭! casperjs配合phantomjs实现自动登录百度,模拟点击等等操作 - 怕虎在线 ...
- maven,本地仓库和私服nexus的配置,以及eclipse载入maven
首先可以进入http://maven.apache.org/官网查看如何配置 一.配置环境 1 确定自己的java运行环境配置正确-->在cmd运行 java -version或echo %JA ...
- mysql记录所有执行过的SQL
前不久,遇见一些问题,要监控一下SQL的执行,看看是不是有哪些SQL是要去掉的之类的 于是我上网找啊找啊,给出来的结果都是一种,修改my.cnf文件 我按着网上的说法去做,结果我直接崩溃了, 也不知道 ...