您的位置:首页 > 其它

poj 1426 栈 广搜

2016-02-01 12:56 148 查看
题目意思很简单  :  就是找一个十进制的数,全由 1 0 组成,是输入那个数字的整数倍
答案有很多种,所以是special judge
需要用到 : 同余取模定理  广搜
因为是广搜我们就可以用栈  当然也可以用数组
#include<stdio.h>#include<queue>using namespace std;void dfs(int x){queue<long long>q;while(!q.empty())q.pop();q.push(1);long long temp=1;while(!q.empty()){if(temp%x==0){printf("%lld\n",temp);return ;}temp=q.front();q.pop();temp=temp*10;q.push(temp+1);q.push(temp);}}int main(){int n;while(scanf("%d",&n),n)dfs(n);return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: