http://poj.org/problem?id=1426

题意 : 输入一个数n,找n的倍数m,这个m所满足的条件是,每一位数只能由0或1组成,在题目的旁边用红色的注明了Special Judge,表示一开始不懂什么意思,后来问的kkk,原来就是,样例的答案真的是样例,只要你输出符合要求的就行,不一定非要输出样例中给的。

思路 : 这个题分类其实是BFS,但在网上看了某大神博客之后瞬间用了DFS做出来了。。。

#include<iostream>
#include<cstdio>
using namespace std ;
int mark ;
void DFS(long long BB,int n ,int floor)
{
if(mark)
return ;
if(BB % n == )
{
//cout<<BB<<endl;
printf("%lld\n",BB) ;
mark = ;
return ;
}
if(floor == )
return ;
DFS(BB*,n,floor+) ;
DFS(BB*+,n,floor+) ;
}
int main()
{
int n ;
while(cin>>n)
{
if(n == ) break ;
mark = ;
DFS(,n,) ;
}
return ;
}

至于到19为什么就回溯了,这个的缘由我也不是很清楚,问了THH,他说是因为无论输入的n是什么,要找一个符合条件的m,都会保持在19位以内,在19位以内肯定会找出一个来

下面这个是kkk提供的方法,用的BFS,很简单的,队列存储,BFS的话,就是遍历10,11,若不符合条件,就在10后边加1位,可为1可为0,就是100或者101,在11后边再加一位,110,或者111,一直这样找下去,知道符合条件为止

#include<queue>
#include<cstdio>
using namespace std;
int n ;
void bfs()
{
long long m,p = ;
queue<long long>Q;
Q.push(p);
while(!Q.empty())
{
p=Q.front();
Q.pop();
for(int i = ;i < ;i++)
{
m=*p+i;
if(m%n==)
{
printf("%lld\n",m);
return ;
}
Q.push(m);
}
}
}
int main()
{
while(~scanf("%d",&n)&&n)
{
if(n == )
{
printf("1\n");
continue;
}
bfs();
}
return ;
}

POJ1426Find The Multiple的更多相关文章

  1. POJ1426Find The Multiple[BFS]

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27433   Accepted: 114 ...

  2. POJ1426-Find The Multiple(搜索)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42035   Accepted: 176 ...

  3. poj1426--Find The Multiple(广搜,智商题)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18527   Accepted: 749 ...

  4. poj-1426-Find The Multiple(打表水过)

    思路: 2的最近可以整除的数是10 所以,很关键的一点,只要是偶数,例如: 6:2*3,可以拆分为能够被2整除和能够被3整除的乘积,所以,10*111=1110 144:72*2,8*9*2,2*2* ...

  5. Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...

    Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...

  6. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  7. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

  8. SharePoint "System.Data.SqlClient.SqlException (0x80131904): Parameter '@someColumn' was supplied multiple times.“

    最近在处理SharePoint Office365的相关开发的时候发现了这样一个奇怪的现象: 无法通过API更新Editor field,只要已更新就会throw Exception,由于是Offic ...

  9. 2012Chhengdu K - Yet Another Multiple Problem

    K - Yet Another Multiple Problem Time Limit:20000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

随机推荐

  1. C++11智能指针

    今晚跟同学谈了一下智能指针,突然想要看一下C++11的智能指针的实现,因此下了这篇博文. 以下代码出自于VS2012 <memory> template<class _Ty> ...

  2. 弹性布局-flex

    浅谈display:flex   display:flex 意思是弹性布局 首先flex的出现是为了解决哪些问题呢? 一.页面行排列布局 像此图左右两个div一排显示 可以用浮动的布局方式 html部 ...

  3. mysql中按string字段排序

    如: Sql代码SELECT * FROM Student WHERE 1 = 1 ORDER BY -ID DESC或者: Sql代码SELECT * FROM Student WHERE 1 = ...

  4. 2.servlet 生命周期

    1.建Web project“2Servlet_Basic” 2.建包com.amaker.servlet 3.建类“ServletBasic.java” package com.amaker.ser ...

  5. linux编程:环境表

    每个进程在启动的时候都会收到一张环境表.环境表是由一个字符指针数组组成,每个指针包含一个以NULL结束的字符串的地址,全局变量environ包含了指针数组的地址: extern char **envi ...

  6. Oracle中排序列中值相同引发的问题(译)

    This queston came up on the Oracle newsgroup a few days ago: 这个问题在Oracle的新闻中心被提出了一段时间: I have a tabl ...

  7. 删除 mysql (rpm)

    http://blog.csdn.net/love__coder/article/details/6894566 a)查看系统中是否以rpm包安装的mysql [root@linux ~]# rpm  ...

  8. 局域网实现 yum

    1 安装squid代理 ##### . 安装squid yum -y remove squid yum -y install squid ##### . 修改配置文件 vi /etc/squid/sq ...

  9. CDH JPS 出现没有名字的进程

    jps 时出现没有名字的进程 或者process information unavailable 把服务关掉,执行一下 rm -rf /tmp/hsperfdata_* 再重启就好了.

  10. Webserver issues | PHP manager for IIS

    4 down vote accepted In order to successfully install the PHP manager for IIS 8, you need the .NET 3 ...