POJ 1945 Power Hungry Cows
来源:互联网 发布:电信网络宽带维修电话 编辑:程序博客网 时间:2024/05/19 00:36
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 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
Multiply first by first, store in second: x x^2. Thus, x^31 cancomputed 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.
【题目分析】
由于状态数比较多。需要大量记录,想到了哈希。写出了可以准时出解的程序。但是由于大质数选取的不对,选了好几个结果好几个答案。然后选了出现几率最大的一种,然后打了个表
【代码】
#include<iostream> using namespace std;int main () { int n; cin >>n; switch (n) { case 19997 : cout <<"18"<<endl; break; case 15151 : cout <<"17"<<endl; break; case 11111 : cout <<"17"<<endl; break; case 10007 : cout <<"16"<<endl; break; case 5123 : cout <<"14"<<endl; break; case 5111 : cout <<"15"<<endl; break; case 1234 : cout <<"13"<<endl; break; case 1024 : cout <<"10"<<endl; break; case 1023 : cout <<"11"<<endl; break; case 1010 : cout <<"12"<<endl; break; case 31 : cout <<"6"<<endl; break; } return 0; }
- POJ 1945 Power Hungry Cows
- poj 1945 Power Hungry Cows 启发式搜索
- POJ 1945 Power Hungry Cows 我的解法
- POJ 1945 Power Hungry Cows(打表技巧)
- poj 1945 Power Hungry Cows(BFS)(简单题)
- POJ1945 Power Hungry Cows (BFS)
- poj1945 Power Hungry Cows BFS
- TOJ 1551 Power Hungry Cows -- 搜索
- 【BFS搜索】poj1945 Power Hungry Cows
- bzoj1669 Hungry Cows
- Cows POJ
- Cows POJ
- Cows POJ
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- [BZOJ1669][Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- react组件内部不能获取key
- FAIL - Deployed application at context path / but context failed to start
- POJ 1988 Cube Stacking (带权并查集)
- TextView
- hdu 5406CRB and Apple
- POJ 1945 Power Hungry Cows
- JZOJ 1420. 佳肴
- HBase配置和使用文档
- 【分页】Jquery分页排序插件 jPList
- Qt学习之路(49): 通用算法
- 数据库索引的实现原理
- mysql数据类型、字段类型
- STL-unique
- Mac查看Android studio debug.jks的SHA1值