hdu4430之枚举+二分
Yukari's Birthday
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2549 Accepted Submission(s): 522
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define INF 99999999
typedef __int64 LL;
using namespace std; const int MAX=1000+10;
LL n; LL cal(LL k,LL r){
LL sum=1,ans=0;
for(int i=1;i<=r;++i){
if(n/sum<k)return n+1;
sum=sum*k;//sum*k可能会溢出
ans+=sum;
if(ans>n)return ans;//ans大于n直接返回
}
return ans;
} LL search(LL i){
LL l=2,r=n;
while(l<=r){
LL mid=(l+r)>>1;
LL sum=cal(mid,i);
if(sum == n-1 || sum == n)return mid;
if(sum<n-1)l=mid+1;
else r=mid-1;
}
return -1;
} int main(){
while(~scanf("%I64d",&n)){
LL a=1,b=n-1;
for(LL i=2;i<=60;++i){//枚举r然后对k进行二分查找,由于k>?=2,2^60>10^12,所以i仅仅要枚举到60就可以
LL k=search(i);
if(k != -1 && i*k<a*b){a=i,b=k;}
}
printf("%I64d %I64d\n",a,b);
}
return 0;
}
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 ...
随机推荐
- 关于MVC视图下拉菜单绑定与取值的问题
绑定视图中dropdownlist: 视图中的代码: @Html.DropDownList("select1") 此处的slect1也就是页面上的<select>< ...
- Android基于HttpUrlConnection类的文件下载
/** * get方法的文件下载 * <p> * 特别说明 android中的progressBar是google唯一的做了处理的可以在子线程中更新UI的控件 * * @param pat ...
- [原创]Toolbar setNavigationIcon无效
最近在做一个Toolbar,setNavigationIcon()这个方法一直无效,说什么的都有,什么getSupportActionBar().setNavigationIcon()的,说设置sty ...
- ajax 实现输入提示效果
网站主页 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- Ruby开发环境的搭建
1.Ruby的下载 https://rubyinstaller.org/downloads/ 2.Ruby的安装 3.Eclipse配置Ruby开发环境 插件地址:http://rubyeclipse ...
- 如何描述bug
清晰的标题 环境描述 已经采取了什么措施 结果 日志 Coredump 截图
- dubbo之延迟暴露
延迟暴露 如果你的服务需要预热时间,比如初始化缓存,等待相关资源就位等,可以使用 delay 进行延迟暴露. 延迟 5 秒暴露服务 <dubbo:service delay="5000 ...
- 我的 Windows 10 的基本配置
Windows 10 的基本配置 功能性 开启 .Net Framework 3.5(包括 .NET 2.0 和 3.0) 旧版本 Windows 10 默认只安装了 .Net Framework 4 ...
- 【sqli-labs】 less57 GET -Challenge -Union -14 queries allowed -Variation4 (GET型 挑战 联合查询 只允许14次查询 变化4)
双引号闭合 http://192.168.136.128/sqli-labs-master/Less-57/?id=1"%23 和less56一样查数据
- 关于css定位的一些总结
#pay_pic{ overflow: hidden; width: 200px; margin: 0 auto; } table.dataintable { margin-top: 15px; bo ...