待解决poj1426 同余模
来源:互联网 发布:学cnc编程 编辑:程序博客网 时间:2024/05/23 14:28
先贴一个没有技术含量的
#include<iostream>#include<stdio.h>#include<queue>using namespace std;long long q[10000000];long long a[204];long long bfs(int n){ int front=0,tail=0; q[tail++]=1; while(1) { long long tmp=q[front++]; if(tmp*10%n==0) return tmp*10; if((tmp*10+1)%n==0) return tmp*10+1; q[tail++]=tmp*10%n; q[tail++]=(tmp*10+1)%n; } return -1;}int main(){ for(int i=0;i<=200;i++) a[i]=bfs(i); int n; while(cin>>n&&n){ cout<<a[n]<<endl;} return 0;}
#include <iostream> #include <queue> #include <string> using namespace std; string ans[210]; bool mark[210]; struct node { string ans; int mod; }; string BFS(int n) { memset(mark,0,sizeof(mark)); queue<node>q; node s; s.ans="1"; s.mod=1; q.push(s); mark[1]=true; while(!q.empty()) { node now=q.front(),temp=now; q.pop(); int c=(now.mod*10+1)%n; int d=(now.mod*10)%n; if(d==0) { temp.ans+="0"; return temp.ans; } if(c==0) { temp.ans+="1"; return temp.ans; } if(!mark[d]) { mark[d]=1; temp.ans+="0"; temp.mod=d; q.push(temp); } if(!mark[c]) { mark[c]=1; now.ans+="1"; now.mod=c; q.push(now); } } } int main() { int n; for(int i=1;i<=200;i++) { if(i&1) ans[i]=BFS(i); else ans[i]=ans[(i>>1)]+"0"; } while (scanf("%d",&n)&&n) { cout<<ans[n]<<endl; } }
先码着 过两天看 貌似内心有点抵触 就是看不会 orz
0 0
- 待解决poj1426 同余模
- 同余模定理解决大数问题(poj1426)
- poj1426 同余模定理+二叉树
- BFS 同余模定理 poj1426
- POJ1426 倍数01 BFS(同余模定理)
- 【练习赛补题】poj1426 【同余定理】【有趣~】
- POJ1426 Find The Multiple(DFS||BFS||同余模定理)
- POJ1426: Find The Multiple(bfs,同余定理)
- POJ1426-Find The Multiple(二叉树BFS + 同余定理)
- 大数+同余模
- 同余模定理
- 同余模定理
- 同余模算术
- 同余模定理
- 模运算与同余
- 【math】同余模方程组
- 同余与模运算
- 同余与模运算
- android lk解读 (2)
- 如何将iphone系统由正式版转为beta测试版
- 一步一步教你如何导出JAR包后将多个JAR包合并,并混淆
- JDBC重要的四大对象
- MySQL 常用相关总结
- 待解决poj1426 同余模
- position的四个属性值: relative ,absolute ,fixed,static
- UIView 中常见的方法总结
- Eclipse + Maven 创建 web项目
- hive 与 sql
- 未登录词的hmm模型切词
- OJ3404数据结构实验之排序七:选课名单
- 综述:游戏优化
- Android中的Environment.getExternalStorageState使用