这个BFS并不是很好想。。 最主要的一点是每个余数只会被拿出来一次更新其他余数, 然后我用d[ i ]表示

到达 i 这个余数最短需要多长,然后从高位往低位贪心,判断成立的时候忘记了如果0被ban掉了这个判断会

出问题,都想到这里了为什么没有想到直接去bfs找答案呢??? 我TM蠢爆。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int n, m, tot, vis[N], from[N], who[N], ans[N];
bool is[];
void init() {
tot = ;
memset(vis, , sizeof(vis));
memset(is, , sizeof(is));
}
int main() {
int cas = ;
while(scanf("%d%d", &n, &m) != EOF) {
init();
for(int i = ; i <= m; i++) {
int x; scanf("%d", &x);
is[x] = true;
}
queue<int> que;
for(int i = ; i < ; i++) {
if(is[i]) continue;
if(i%n==) {
ans[tot++] = i;
break;
}
vis[i%n] = ;
from[i%n] = ;
who[i%n] = i;
que.push(i%n);
}
if(!tot) {
while(!que.empty() && !tot) {
int u = que.front(); que.pop();
for(int i = ; i < ; i++) {
if(is[i]) continue;
int v = (u*+i)%n;
if(!v) {
ans[tot++] = i;
while(u) {
ans[tot++] = who[u];
u = from[u];
}
reverse(ans, ans + tot);
break;
}
if(vis[v]) continue;
vis[v] = vis[u] + ;
from[v] = u;
who[v] = i;
que.push(v);
}
}
}
printf("Case %d: ", cas++);
if(!tot) puts("-1");
else {
for(int i = ; i < tot; i++)
printf("%d", ans[i]);
puts("");
}
}
return ;
} /*
*/

HDU - 4474 bfs好题的更多相关文章

  1. Saving Princess claire_(hdu 4308 bfs模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...

  2. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  3. BFS简单题套路_Codevs 1215 迷宫

    BFS 简单题套路 1. 遇到迷宫之类的简单题,有什么行走方向的,先写下面的 声明 ; struct Status { int r, c; Status(, ) : r(r), c(c) {} // ...

  4. POJ-2251 Dungeon Master (BFS模板题)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  5. hdu 4531 bfs(略难)

    题目链接:点我 第一次不太清楚怎么判重,现在懂了,等下次再做 /* *HDU 4531 *BFS *注意判重 */ #include <stdio.h> #include <stri ...

  6. HDU 4474 Yet Another Multiple Problem【2012成都regional K题】 【BFS+一个判断技巧】

    Yet Another Multiple Problem Time Limit: 40000/20000 MS (Java/Others)    Memory Limit: 65536/65536 K ...

  7. hdu 4474 大整数取模+bfs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4474 (a*10+b)%c = ((a%c)*10+b%c)%c; 然后从高位开始枚举能填的数字填充, ...

  8. HDU 1312 (BFS搜索模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1312 题目大意:问迷宫中有多少个点被访问. 解题思路: DFS肯定能水过去的.这里就拍了一下BFS. ...

  9. HDU 4474 Yet Another Multiple Problem ( BFS + 同余剪枝 )

    没什么巧办法,直接搜就行. 用余数作为每个节点的哈希值. #include <cstdio> #include <cstring> #include <cstdlib&g ...

随机推荐

  1. 把数组存入到cookie中

    $arr = array(1,2,3); // 把数组序列化之后,存入到cookie中 $arr_str = serialize($arr); // 序列化数组 setcookie('a',$arr_ ...

  2. C语言入门教程-(2)基本程序结构

    1.简单的C语言程序结构 要建造房屋,首先需要打地基.搬砖搭建框架(这大概就是为什么叫搬砖的原因).学习计算机语言的时候也一样,应该从基本的结构开始学起.下面,我们看一段简单的源代码,这段代码希望大家 ...

  3. Struts S2-052漏洞利用之Meterpreter(CVE-2017-9805)

    Struts S2-052漏洞爆出来已经快一周了,大家可能更想知道其危害~鸡肋? 这里就直接给出漏洞利用拿Meterpreter的过程,想了解更多的请参考其他文章,下面是实验演示部分.Struts S ...

  4. http Get和Post请求方式

      string postURL ="http://xxxxx.ashx"; List<string> paramName = new List<string&g ...

  5. 写给“有钱大爷”、”美工殿下”、“前端文艺青年”的微信HTML5页面设计建议

    ==============================   2018更新 iphone X 的设计内容   ==============================     我保证你一分钟就 ...

  6. Openflow Plugin学习笔记3

    MDController.java 中的start方法,创建了SwitchConnectionHandlerImpl实例 SwitchConnectionHandlerImpl switchConne ...

  7. 解决windows文件夹不能自动刷新的问题

    我用的是win7系统,最近忽然发现我的文档文件夹里的文件不能自动刷新了,就是当剪切或删除某个文件后,文件夹里的文件没有变化,看起来文件还在原文件夹中,只有通过手动刷新后才能看到效果,该如何解决? 网上 ...

  8. git checkout 命令详解【转】

    转自:http://www.cnblogs.com/hutaoer/archive/2013/05/07/git_checkout.html 在日常的git操作中,git checkout——检出,是 ...

  9. aarch64_m3

    mrpt-stereo-camera-calibration-1.4.0-1.fc26.aarch64.rpm 2017-03-17 10:02 143K fedora Mirroring Proje ...

  10. 一步一步搭建11gR2 rac+dg之安装rac出现问题解决(六)【转】

    一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + dg 之安装rac出现的问题 (六) 本文转自 一步一步搭建11gR2 rac+dg之 ...