题目传送门

题意:问使得sum (k^i) = n || n -1 (1 <= i <= r) 的min (r*k)组合的r和k 

分析:r的最大不会超过40,枚举r,二分搜索k。注意会爆long long,所以上界需要优化。r = 2开始上界就小于1e6,cyd将后面的范围也求出来了,其实1e6就够用了。

这水题卡了我好久,没有很好分析题目,做不出来就有种无力感,开始烦躁起来。还是题目做得少了,如果这种题做多了,可能看一眼就能做出来了。

/************************************************
* Author :Running_Time
* Created Time :2010-1-16 12:18:59
* File Name :K.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);
ll n, r, k; ll cal(ll x, int y) {
ll ret = 0, p = x;
for (int i=1; i<=y; ++i) {
ret = ret + p;
p *= x;
if (ret > (ll)1e12) return ret;
}
return ret;
} ll bsearch(ll l, ll r, int m, ll ans) {
while (l <= r) {
ll mid = (l + r) >> 1;
ll sum = cal (mid, m);
if (sum == ans) return mid;
else if (sum < ans) l = mid + 1;
else r = mid - 1;
}
return 0;
} int main(void) {
while (scanf ("%lld", &n) == 1) {
r = 1; k = n - 1; ll kk;
for (int i=2; i<=40; ++i) {
kk = bsearch (2, 1e6, i, n);
if (kk == 0) continue;
if (1ll * i * kk < r * k) {
r = i; k = kk;
}
}
for (int i=2; i<=40; ++i) {
kk = bsearch (2, 1e6, i, n - 1);
if (kk == 0) continue;
if (1ll * i * kk < r * k) {
r = i; k = kk;
}
}
printf ("%lld %lld\n", r, k);
} return 0;
}

  

二分搜索 UVALive 6076 Yukari's Birthday (12长春K)的更多相关文章

  1. 状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)

    题目传送门 题意:采蘑菇.现在采了n座山,共5座山,最后要求有三个篮子的蘑菇量是1024的整数倍,丢掉后一直减1024直到不超过1024 分析:n <= 3时直接1024,否则状压枚举哪三个篮子 ...

  2. 12、K最近邻算法(KNN算法)

    一.如何创建推荐系统? 找到与用户相似的其他用户,然后把其他用户喜欢的东西推荐给用户.这就是K最近邻算法的分类作用. 二.抽取特征 推荐系统最重要的工作是:将用户的特征抽取出来并转化为度量的数字,然后 ...

  3. 后端程序员之路 12、K最近邻(k-Nearest Neighbour,KNN)分类算法

    K最近邻(k-Nearest Neighbour,KNN)分类算法,是最简单的机器学习算法之一.由于KNN方法主要靠周围有限的邻近的样本,而不是靠判别类域的方法来确定所属类别的,因此对于类域的交叉或重 ...

  4. 【暑假】[实用数据结构]UVAlive 3644 X-Plosives

    UVAlive X-Plosives 思路:    “如果车上存在k个简单化合物,正好包含k种元素,那么他们将组成一个易爆的混合物”  如果将(a,b)看作一条边那么题意就是不能出现环,很容易联想到K ...

  5. nyoj914Yougth的最大化(二分搜索 + 贪心)

    Yougth的最大化 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价值最大吗 ...

  6. Docker容器学习与分享12

    Docker多主机管理 之前在一台Centos7上安装了Docker,如果是在多台主机上都安装Docker,用手动安装的方法不光效率低下,而且有可能出错,所以可以使用Docker Machine进行多 ...

  7. 二分搜索 POJ 1064 Cable master

    题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...

  8. Period UVALive - 3026

    For each prefix of a given string S with N characters (each character has an ASCII code between 97 a ...

  9. UVALive 3902 Network (树+dfs)

    Consider a tree network with n nodes where the internal nodes correspond to servers and the terminal ...

随机推荐

  1. 1009: josephus问题

    1009: josephus问题 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 549  Solved: 227 Description josephus ...

  2. 在iOS7中修改状态栏字体的颜色

    http://www.2cto.com/kf/201408/324442.html 默认状态栏的字体为黑色:UIStatusBarStyleDefault 状态栏的字体为白色:UIStatusBarS ...

  3. 一个csrf实例漏洞挖掘带你了解什么是csrf

    [-]CSRF是个什么鬼? |___简单的理解: |----攻击者盗用了你的身份,以你的名义进行某些非法操作.CSRF能够使用你的账户发送邮件,获取你的敏感信息,甚至盗走你的财产. |___CSRF攻 ...

  4. BZOJ 3540 realtime-update 解题

    分析一下题意,大约是给定一串牛,然后找到一个跨越距离最长的牛子串使得在这个范围内白牛和花牛一样多. 白牛可以任意涂成花牛. 既然"白牛可以任意涂成花牛",那么我们需要找到一个最长的 ...

  5. encode与decode,unicode与中文乱码的问题

    encode是指将unicode字符编码成其他字符集的字符,如utf-8,ascii等: 而decode是指将其他字符编码,如utf-8转换成unicode编码. encode是指将人类用的语言(字符 ...

  6. linux下cp目录时排除一个或者多个目录的方法

    说明:/home目录里面有data目录,data目录里面有a.b.c.d.e五个目录,现在要把data目录里面除过e目录之外的所有目录拷贝到/bak目录中 系统运维 www.osyunwei.com ...

  7. 一些Linux的路径

    系统引导时启动        /etc/rc.d/rc.local

  8. Sybase IQ如何将大文件数据迅速加载到数据库

    试想一下,如果一个文件5G.10G甚至更大.如何将它迅速地加载到数据库指定的表呢?我们看看Sybase IQ是如何迅速地将表的数据加载到数据库的. 数据文件格式: 1440,2011-01-09 00 ...

  9. iOS CALayer动画中使用的3个tree

    在网上经常看到关于layer的tree的描述,不太理解,今天找到了官方文档,原文在Core Animation Programming Guide 中. Layer Trees Reflect Dif ...

  10. ini 文件操作记要(1): 使用 TIniFile

    ini 文件操作记要(1): 使用 TIniFile unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Class ...