uva 1374 快速幂计算
2015-02-17 22:12
197 查看
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <cstdlib> #include <stack> #include <cctype> #include <string> #include <malloc.h> #include <queue> #include <map> using namespace std; const int INF = 0xffffff; const double esp = 10e-8; const double Pi = 4 * atan(1.0); const int Maxn = 2000+10; const long long mod = 2147483647; const int dr[] = {1,0,-1,0,-1,1,-1,1}; const int dc[] = {0,1,0,-1,1,-1,-1,1}; typedef long long LL; LL gac(LL a,LL b){ return b?gac(b,a%b):a; } int n,ans[Maxn],maxd; bool vis[Maxn]; int dfs(int step,int s){ ans[step] = s; if(step == maxd){ if(vis ) return 1; return 0; } if(ans[step] > 2000 || s * 1 << (maxd-step) < n){ return 0; } for(int i = 0;i<= step;i++){ int t = s + ans[i]; if(!vis[t]){ vis[t] = 1; if(dfs(step+1,t)) return 1; vis[t] = 0; } t = abs(s-ans[i]); if(t > 0 && !vis[t]){ vis[t] = 1; if(dfs(step+1,t)) return 1; vis[t] = 0; } } return 0; } int main() { #ifndef ONLINE_JUDGE freopen("inpt.txt","r",stdin); #endif while(~scanf("%d",&n) && n){ for(maxd = 0;;maxd++){ memset(vis,0,sizeof(vis)); vis[1] = 1; if(dfs(0,1)){ printf("%d\n",maxd); break; } } } return 0; }View Code
相关文章推荐
- uva1374 快速幂计算 迭代加深优先逼近
- [IDA*] UVa1374 Power Calculus 快速幂计算
- 紫书 例题 7-13 快速幂计算 UVA1374 IDA*搜索
- UVa11582 巨大的斐波那契数 循环节计算+快速幂
- UVA1374(Power Calculus|快速幂计算)=》迭代加深搜
- UVA UVA - 1374 Power Calculus 快速幂计算(迭代加深搜索)
- Uva1374 Power Calculus(快速幂计算)【IDA*】【例题7-13】
- UVa1374(快速幂)
- UVa 1374 - Power Calculus——[迭代加深搜索、快速幂]
- UVa 1374 快速幂计算(dfs+IDA*)
- UVa 1374 Power Calculus (快速幂计算)
- 例题7-13 快速幂计算(Power Calculus, ACM/ICPC Yokohama 2006, UVa1374)
- 1097: 树状数组1(快速求和计算)
- uva 10006 快速幂
- uva 10655 Algebraic Problem(矩阵快速幂)
- UVA 12470 - Tribonacci(快速幂矩阵)
- Strassen矩阵乘法 + 快速计算乘方的算法 + 矩阵的次幂
- uva 1342 欧拉定理(计算几何模板)
- 快速计算平台matlab到C++ 代码转换
- 计算几何专项:UVa 811