HDU 4430 Yukari's Birthday (二分)
题意:有 n 个蜡烛,让你插到蛋糕上,每一层要插 k^i个根,第0层可插可不插,插的层数是r,让 r * k 尽量小,再让 r 尽量小,求r 和 k。
析:首先先列出方程来,一个是不插的一个是插的,比如插的是 sigam(0, r, k^i) = n,然后 r 比较小,可以枚举 r,然后二分求 k。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const LL mod = 1e12 + 10;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
LL n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} LL judge(int mid, int r){
LL sum = 0, t = mid;
for(int i = 1; i <= r; ++i, t *= mid){
sum += t;
if(sum > mod) return mod;
}
return sum;
} int main(){
while(cin >> n){
int ans = INF;
int k = 0, rr;
for(int i = 2; i < 41; ++i){
int l = 1, r = (int)sqrt(n+0.5) + 1;
int ttt = 0;
while(l <= r){
int mid = l + r >> 1;
LL t = judge(mid, i);
if(t == n || t == n-1){ ttt = mid; break; }
else if(t < n-1) l = mid + 1;
else r = mid - 1;
}
if(ttt > 0 && ttt * i < ans){
ans = ttt * i;
k = ttt;
rr = i;
}
}
if(k == 0 || k == 1) printf("1 %I64d\n", n-1);
else printf("%d %d\n", rr, k);
}
return 0;
}
HDU 4430 Yukari's Birthday (二分)的更多相关文章
- 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(二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4430 题目大意:给定n个蜡烛,围绕蛋糕的中心插同心圆,从里往外分别是第1圈.第2圈....第r圈,第 ...
- hdu 4430 Yukari's Birthday (简单数学 + 二分)
Problem - 4430 题意是,给出蜡烛的数量,要求求出r和k,r是蜡烛的层数,k是每一层蜡烛数目的底数. 开始的时候,没有看清题目,其实中间的那根蜡烛是可放可不放的.假设放置中间的那根蜡烛,就 ...
- 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(二分+枚举)
题意:已知有n个蜡烛,过生日在蛋糕上摆蜡烛,将蜡烛围成同心圆,每圈个数为ki,蛋糕中心最多可摆一个蜡烛,求圈数r和看,条件为r*k尽可能小的情况下,r尽可能小. 分析:n最大为1012,k最少为2,假 ...
- hdu 4430 Yukari's Birthday
思路: 分析知道1<=r<40:所以可以枚举r,之后再二分k. 代码如下: #include<iostream> #include<stdio.h> #includ ...
- hdu 3433 A Task Process 二分+dp
A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 3622 Bomb Game(二分+2-SAT)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4430 & ZOJ 3665 Yukari's Birthday(二分法+枚举)
主题链接: HDU:pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430 ...
随机推荐
- git 查看、创建、切换、删除、重命名和推送分支
1.查看本地所有分支:前面有 “*” 的是当前所处的分支 $ git branch test-A * test-B 2.查看本地和远程服务器的所有分支: $ git branch -a test-A ...
- 【openCV学习笔记】【2】读取并播放一段视频
#include <iostream> #include <opencv/highgui.h> int main(int argc, char** argv){ cvNamed ...
- 【openCV学习笔记】在Mac上配置openCV步骤详解
(1)安装Homebrew:(需要Ruby) 注:因为snow leopard 以后已经自带Ruby了,所有可以不用自己安装Ruby. 看一下Homebrew的官网: http://mxcl.gith ...
- JS 获取鼠标坐标
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- java代码练习======每隔5行打印数字
总结:当我们感觉数字排列横排,竖排不好看的时候,学会空几行在排列,哎呦,效果不错喔 package com.aa; public class West2 { public static void ma ...
- php中mb_strlen,mb_substr根据中文长度截取字符串
大于8截取,小于等于则不截取. 结合thinkphp模板引擎规则,代码如下: <,,'utf-8'}..<else/>{sh:$vo.name}</if> 这里if中的函 ...
- Unity3D 4.3在Windows下打包iOS资源
想当年,想弄iOS的版本必须弄台mac机器,虽然一开始要弄iOS的时候觉得在mac上开发感觉挺高富帅的,但是做多了之后就觉得在mac上开发各种不方便.现在好了,Unity3D 4.3开始支持在Wind ...
- Bokeh绘图
http://bokeh.pydata.org/en/latest Bokeh 是一个专门针对Web浏览器的呈现功能的交互式可视化Python库.这是Bokeh与其它可视化库最核心的区别. 专门针对 ...
- Django项目部署-01
1. 安装Python 下载链接:https://www.python.org/getit/ 我这边下载的是3.6.5的版本的执行版本,安装过程中选择自动安装pip 2.安装django pip in ...
- MYCAT实战之分片迁移
实践扩容 1.要求: travelrecord 表定义为10个分片,尝试将10个分片中的 2 个分片转移到第二台MySQL上, 并完成记录要求,最快的数据迁移做法,中断业务时间最短 2.针对分片以及迁 ...