Power Hungry Cows
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 4570 Accepted: 1120

Description

FJ's cows would like to be able to compute integer powers P (1 <= P <= 20,000) of numbers very quickly, but need your help. Because they're going to be computing powers of very large numbers, they can only keep around two work variables for intermediate results.

The first of those work variables is initialized to the number (denoted x) for which they are calculating the power; the other is initialized to 1. The cows can both multiply and divide any pair of the work variables and store the result in any work variable, but all results are stored as integers.

For example, if they want to compute x^31, one way to perform the calculation is:

WV1 WV2
Start: x 1
Multiply first by first, store in second: x x^2
Multiply second by second: x x^4
Multiply second by second: x x^8
Multiply second by second: x x^16
Multiply second by second: x x^32
Divide second by first: x x^31

Thus, x^31 can computed in six operations. Given the power to be computed and the the number of work variables, find the minimum number of operations to calculate the power.

Input

A single line with one integer: P.

Output

A single line with a single integer that is the minimum number of operations it requires to compute the power.

Sample Input

31
Sample Output

6

Source

USACO 2002 February

分析:先bfs然后发现各种乱搞都不行……然后本渣去打表……悲剧的是最后的表太大了poj上交不去……然后找到了这个神一般的东西Orz http://www.cppblog.com/varg-vikernes/archive/2010/02/18/108024.aspx 额不过最后启发式搜索水过的……

[USACO2002][poj1945]Power Hungry Cows(启发式搜索)的更多相关文章

  1. 『Power Hungry Cows A*启发式搜索』

    Power Hungry Cows(POJ 1945) Description FJ的奶牛想要快速计算整数P的幂 (1 <= P <=20,000),它们需要你的帮助.因为计算极大数的幂, ...

  2. 【BFS】Power Hungry Cows

    Power Hungry Cows Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5522   Accepted: 1384 ...

  3. poj 1945 Power Hungry Cows A*

    Description:     就是给你一个数,你可以把它自乘,也可以把他乘或除以任意一个造出过的数,问你最多经过多少次操作能变换成目标数 思路:这题真的不怎么会啊.n = 20000,每一层都有很 ...

  4. BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛

    1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 665  Solved: 419 ...

  5. BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛( LIS )

    裸的LIS ----------------------------------------------------------------- #include<cstdio> #incl ...

  6. 【动态规划】bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛

    #include<cstdio> #include<algorithm> using namespace std; int n,a[5001],b[5001],en; int ...

  7. 【BZOJ】1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛(lis)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1669 水题太严重 #include <cstdio> #include <cstr ...

  8. bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】

    最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #in ...

  9. 【极大化剪枝】Power Hungry Cows-C++【没有用A*!】【超级简单!】

    Description小KITTY想要快速计算整数P的幂 (1 <= P <=10,000),它们需要你的帮助.因为计算极大数的幂,所以它们同一时间仅能使用2个存储器,每个存储器可记录某个 ...

随机推荐

  1. 【node.js】安装express后,'express' 不是内部或外部命令的问题

    因express默认安装是最新的版本,已经是4.x.x的版本.而最新express4.0+版本中将命令工具分出来了,所以必须要安装express-generator,执行: D:\TOOLS\Node ...

  2. zabbix安装排错过程

    在讲安装过程之前需要先把zabbix的工作流程简单的讲一遍:zabbix是个开源监控软件,通过web才能更直观的监控我们想要监控的主机,同时,zabbix从被监控主机获取到的信息需要存放在数据库中,因 ...

  3. 22 扩展Python - 《Python 核心编程》

  4. 使用SSIS包调度开发的包

    在项目中,开发完自己的packages之后,需要使用agentjob之类的服务来调度自己的package,当然我们也可以使用一个package来调度这些,下面就是我的一个简单的尝试. 没有设计得像Ag ...

  5. RabbitMQ基本概念和使用

    RabbitMQ是一个消息代理,核心原理:发送消息,接收消息. RabbitMQ主要用于组件之间的解耦,消息发送者无需知道消息使用者的存在,反之亦然.   单向解耦                   ...

  6. 边工作边刷题:70天一遍leetcode: day 71-3

    Two Sum I/II/III 要点:都是简单题,III就要注意如果value-num==num的情况,所以要count,并且count>1 https://repl.it/CrZG 错误点: ...

  7. POJ 3233 Matrix Power Series --二分求矩阵等比数列和

    题意:求S(k) = A+A^2+...+A^k. 解法:二分即可. if(k为奇)  S(k) = S(k-1)+A^k else        S(k) = S(k/2)*(I+A^(k/2)) ...

  8. GitLab/Git在AndroidStudio上的使用(转)

    1.在AndroidStudio上的配置GitLab 1)首先先将gitlab上的开发项目clone到本地(可以使用命令行或者管理工具,具体操作在GitLab中已经涉及,这里不再赘述),然后导入到An ...

  9. winform listbox与textbox组合提示框 模糊查询

      private void listbox1_MouseClick(object sender, MouseEventArgs e)        {            textbox1.Vis ...

  10. 入门Linux

    45分钟带你入门Linux(附:笔者在工作室开讨论班录制的视频讲解)   第一部分    熟悉Linux基本操作 一.初识Linux 1.Linux特点 ◊  开放性 ◊  多用户 ◊  多任务 ◊  ...