zoukankan      html  css  js  c++  java
  • [USACO2002][poj1945]Power Hungry Cows(启发式搜索)

    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 额不过最后启发式搜索水过的……

  • 相关阅读:
    Oralce两种认证方式的总结
    MOSS2007启用发布Feature后,子站点标签无法高亮
    c#事务的使用、示例及注意事项 转
    软件标准项目文档(转)
    .net常用JS代码
    Epplus
    MOSS2007中自定义页面
    步步为营 SharePoint 开发学习笔记系列总结(转)
    SharePoint 2010 自定义Ribbon实现文档批量下载为Zip文件(转)
    显示详细的SharePoint错误
  • 原文地址:https://www.cnblogs.com/wmrv587/p/3583509.html
Copyright © 2011-2022 走看看