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 ...
随机推荐
- EF 批量插入,sqlhelper 批量插入
需添加一个using System.Linq; 引用 public void BulkInsert<T>(string connection, string tableName, ILis ...
- 来自一个用户的体验-Alpha项目测试
软件梦之队成员:201731062305 周蓉 这个作业属于哪个课程 <课程的链接> 这个作业要求在哪里 <作业要求的链接> 团队名称 <软件梦之队>(附上团队博客 ...
- Android popwindow 消失监听
LisviewPop.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { //改变显示 ...
- 解决Sql Server 日志满了,设置收缩
解决Sql Server 日志满了,设置收缩: --查看文件占用空间 . '文件大小(MB)',* from sysfiles; ALTER DATABASE SpyData SET RECOVERY ...
- html5——表单
type类型 email //输入email格式 tel //手机号码 url //只能输入url格式 number //只能输入数字 search //搜索框 range //范围 滑动条 colo ...
- JS——sort
1.a-b升序 <script> var arr = [2, 3, 1, 5, 0]; function compare(a, b) { return a - b; } console.l ...
- 常用MySQL语句整合
常用MySQL语句整合 1. MySQL服务的配置和使用 修改MySQL管理员的口令:mysqladmin –u root password 密码字符串 如:mysqldmin –u root pas ...
- python PIL相关操作
项目中需要用python生成二维码,这里记录一下相关PIL相关操作. RGBA问题: 需要将图片A粘贴到图片B上,之前没有注意透明度问题,A的背景是透明的,粘贴到B上后,A的周围是黑的.后来才发现是P ...
- 打造最强NGINX HTTPS
SSL LABS 检测 完整配置如下 server { listen 443 ssl; server_name xxx.xxxke.com; ssl on; ssl_certificate /xxx/ ...
- codeforces_738D
D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...