hdu 4474 bfs
来源:互联网 发布:节奏大师网络拦截 编辑:程序博客网 时间:2024/06/14 13:30
#include <iostream>#include <string>#include <string.h>#include <stdio.h>#include <algorithm>#include <queue>#include <stdlib.h>class HDU4474{ public : const static int N = 10008 ; bool del[10] ; bool vis[N] ; int father[N] ; char text[N] ; int cas = 1 ; int n ; void solve(){ int x , m ; while(scanf("%d%d" , &n , &m) != EOF){ std::fill(del , del + 10 , false) ; for(int i = 0 ; i < m ; i++){ scanf("%d" , &x) ; del[x] = true ; } printf("Case %d: " , cas++ ) ; if(bfs()) printf("%s\n" , ans().c_str() ) ; else printf("%d\n" , -1) ; } } bool bfs(){ std::fill(vis , vis + N , false) ; std::queue<int> q ; q.push(0) ; while(! q.empty()){ int u = q.front() ; q.pop() ; for(int i = 0 ; i <= 9 ; i++){ if(del[i] || (u == 0 && i == 0)) continue ; int mod = (u * 10 + i ) % n ; if(vis[mod]) continue ; vis[mod] = true ; text[mod] = ('0' + i) ; father[mod] = u ; q.push(mod) ; if(mod == 0) return true ; } } return false ; } std::string ans(){ std::string sb = "" ; int u = 0 ; while(u != 0 || sb.length() == 0){ sb += text[u] ; u = father[u] ; } std::reverse(sb.begin() , sb.end()) ; return sb ; }} ;int main(){ HDU4474 task ; task.solve() ; return 0;}
0 0
- HDU 4474 BFS
- hdu 4474 搜索bfs
- hdu 4474 bfs
- hdu 4474 数位BFS
- hdu 4474 BFS+思维题
- hdu 4474 数位搜索bfs
- HDU bfs
- hdu 4474 Yet Another Multiple Problem bfs
- hdu 4474 Yet Another Multiple Problem (bfs)
- hdu 4474 Yet Another Multiple Problem(BFS)
- HDU 4474(神奇的BFS+强剪枝)
- HDU 4474 Yet Another Multiple Problem BFS
- HDU 4474 同余模定理+BFS
- hdu 1175 bfs
- HDU 1072(BFS)
- HDU 1429(BFS )
- hdu 1026(BFS)
- HDU 4039 BFS
- Halcon腐蚀膨胀算子
- 排序算法
- 使用PipedInputStream 和 PipedOutputStream 上传文件,并更新进度
- 【Servlet开发】servlet的请求与响应(二)
- mybatis注解详解
- hdu 4474 bfs
- java 路径分隔符
- 递归
- Android学习笔记--RecycleView用法
- POJ 2392 Space Elevator 排序+多重背包
- Android handler示例
- linux jdk安装配置
- 记毕业感悟160727
- WebGL学习笔记(二)