POJ 1426.Find The Multiple
来源:互联网 发布:ios移动网络下上传图片 编辑:程序博客网 时间:2024/06/07 00:05
题目:http://poj.org/problem?id=1426
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0xfffffff#define MAXN 100005using namespace std;int n;unsigned __int64 ans;bool flag;void dfs(unsigned __int64 x, int deepth){if(deepth>19||flag)return;if(x%n==0){ans = x;flag = true;}else{dfs(x*10,deepth+1);dfs(x*10+1,deepth+1);}}int main(){ while(cin>>n){ if(n==0)break; flag = false; dfs(1,1); cout<<ans<<endl;}}总结: 很坑的一道题目, 如果不用打表的话. 看懂题目后直接想到的就是用bfs来做, bfs队列里存放长度为100的字符串, 每次分两种情况, 在字符串后面接1或者接0. 这样做提交之后MLE了, 想着应该是字符串太大了. 看了很多解题报告后发现, 解的长度在无符号64位int内可以表示(经打表验证, 长度最长的是n=198时共18位), 于是直接用unsigned __int64代替字符串来bfs, 结果超时了(所以又是STL背锅吗). 然后换成dfs就AC了(很迷).
阅读全文
0 0
- POJ 1426.Find The Multiple
- poj find the multiple
- Find The Multiple POJ
- POJ.Find The Multiple
- Find The Multiple POJ
- Find The Multiple POJ
- Find The Multiple POJ
- Find The Multiple POJ
- Find The Multiple POJ
- Find The Multiple POJ
- POJ-Find The Multiple
- 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
- MySQL数据类型和常用字段属性总结
- 软工文档感受----可行性研究报告
- OkHttpClient网络请求
- Android拨打电话
- python: iter、next函数
- POJ 1426.Find The Multiple
- prometheus学习笔记(三)
- D. Almost Identity Permutations(dp)
- C++链接数据库找不到mysql.h
- 请求当前网络状态
- (转)塔析|全球首个比特币借记卡先驱--Xapo
- 数据库学习6
- Tensor, Variable 和Parameter
- 第八章El表达式第二节el表达式访问4种范围属性