POJ - 1426 Find The Multiple 【DFS】
题目链接
http://poj.org/problem?id=1426
题意
给出一个数 要求找出 只有 0 和 1 组成的 十进制数字 能够整除 n
n 不超过 200 十进制数字位数 不超过100
思路
其实 十进制数字位数 不超过 20 下就有可以满足的答案 所以直接用 unsinged long long 就可以过了
。。
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-30;
const int INF = 0x3f3f3f3f;
const int maxn = 5e4 + 5;
const int MOD = 1e9 + 7;
int n;
ull ans;
void dfs(ull x, int cur)
{
if (ans)
return;
if (cur > 19)
return;
if (x % n)
{
dfs(x * 10, cur + 1);
dfs(x * 10 + 1, cur + 1);
}
else
{
ans = x;
return;
}
}
int main()
{
while (scanf("%d", &n) && n)
{
ans = 0;
dfs(1, 0);
cout << ans << endl;
}
}
POJ - 1426 Find The Multiple 【DFS】的更多相关文章
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- POJ 1426 Find The Multiple (DFS / BFS)
题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...
- POJ 1426 Find The Multiple (dfs??!!)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- POJ 1979 Red and Black【DFS】
标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include< ...
- DFS/BFS(同余模) POJ 1426 Find The Multiple
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...
- POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
随机推荐
- ofstream的使用方法
ofstream的使用方法ofstream是从内存到硬盘,ifstream是从硬盘到内存,其实所谓的流缓冲就是内存空间; 在C 中,有一个stream这个类,所有的I/O都以这个“流”类为基础的,包 ...
- python 工具 字符串转numpy浮点数组
不同的数字之间使用 空格“ ”,“$”,"*"等隔开,支持带小数点的字符串NumArray=str2num(LineString,comment='#')将字符串中的所有非Doub ...
- hibernate uuid
- POJ 题目3264 Balanced Lineup(RMQ)
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 39046 Accepted: 18291 ...
- Ubuntu搭建Http服务器
一句命令: sudo apt-get install apache2 产生的启动和停止文件是:/etc/init.d/apache2 启动:sudo apache2ctl -k start 停止:su ...
- VueJS条件语句:v-if、v-else、v-else-if
HTML:if-else <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- Struts2学习八----------接收参数
© 版权声明:本文为博主原创文章,转载请注明出处 接收参数 - 使用Action的属性接收参数 - 使用Domain Model接收参数 - 使用ModelDriven接收参数 实例 1.项目结构 2 ...
- 解决phpmyadmin导入大数据库出现一系列问题
在用phpmyadmin导入mysql数据库文件时,往往超过2M就会提示文件大,导入不成功.这时我们打开phpmyadmin-->libraries-->config.default.ph ...
- jquery中的clone()方法
jquery中不能直接把选择到的元素如$('div')添加到其他地方,而需要使用$('div')[0]等 clone()方法直接复制HTML代码,所以可以直接用来添加元素.
- session 购物车
package session; import java.io.IOException;import java.util.ArrayList;import java.util.List; import ...