POJ 1426 Find The Multiple
来源:互联网 发布:php 开源 报表系统 编辑:程序博客网 时间:2024/04/29 20:06
/*这道题要解决的一个问题就是当数字太大的时候int存下了,不能直接进行模运算可以用这个公式:(a*b)%n=(a%n * b%n)%n(a+b)%n=(a%n + b%n)%n*/#include<stdio.h>#include<string>#include<queue>using namespace std;typedef struct {int mod;string ans;}Node;Node node[210],temp,now;bool dis[210];void bfs(int i) {int x,y;queue<Node> q;memset(dis,false,sizeof(dsi));dis[1]=true;temp.ans="1";temp.mod=1;q.push(temp);while(!q.empty()) {now=temp=q.front();q.pop();x=(temp.mod*10+1)%i;y=(temp.mod*10)%i;if (!x) {node[i].ans=temp.ans+"1";return;}if (!y) {node[i].ans=temp.ans+"0";return;}if (!dis[x]) {temp.ans=temp.ans+"1";temp.mod=x;q.push(temp);dis[x]=true;}if (!dis[y]) {now.ans=now.ans+"0";now.mod=y;q.push(now);dis[y]=true;}}}int main() {int i,n;node[1].ans="1";for(i=2;i<=200;i++) {if (i%2==0) node[i].ans=node[i/2].ans+"0";//因为n的取值范围有限,直接事先计算出来else bfs(i);}while(scanf("%d",&n) && n) {cout<<node[n].ans<<endl;}return 0;}
0 0
- poj 1426 Find The Multiple
- Poj 1426 Find The Multiple
- POJ 1426 Find the Multiple
- poj 1426Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- poj - 1426 - Find The Multiple
- POJ 1426 Find The Multiple
- POJ-1426-Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- poj 1426 Find The Multiple
- POJ 1426 Find The Multiple
- 手势 iOS
- 中文在C/C++中的处理和汉字乱码问题(wchar_t)
- 第11周上机实践项目6——回文、素数(1~3)
- cell 重用
- 记下来
- POJ 1426 Find The Multiple
- Java 安全模型学习(一)
- NSNotificaiton
- MAC下用eclipse编译cocos2d-x项目
- python字符串编码判断
- spring学习5- Container Extension Points(BeanPostProcessor 与BeanFactoryPostProcessor)
- UIView iOS 总结
- 安装sharepoint顺序
- scala-上界