zoj1530 bfs
//Accepted zoj1530 270ms 40008KB
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
;
string a[imax_n];
int vis[imax_n];
queue<int > q;
queue<string >sq;
void bfs(int n)
{
if (a[n]!="") return ;
while (!q.empty()) q.pop();
while (!sq.empty()) sq.pop();
q.push();
sq.push(");
)
{
int x=q.front();
q.pop();
string s=sq.front();
sq.pop();
)
{
a[n]=s;
return ;
}
q.push(*x%n);
sq.push(s+");
q.push((*x+)%n);
sq.push(s+");
}
}
int main()
{
int n;
while (scanf("%d",&n),n)
{
bfs(n);
cout<<a[n]<<endl;
}
;
}
//Accepted zoj1530 110ms 4544kB
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
;
long long a[imax_n];
queue<long long > q;
void bfs()
{
;
while (!q.empty()) q.pop();
q.push();
)
{
long long x=q.front();
q.pop();
;i<=;i++)
&& x%i==)
{
a[i]=x;
cnt++;
}
) return ;
q.push(*x);
q.push(*x+);
}
}
int main()
{
bfs();
int n;
//for (int i=1;i<=200;i++)
//{
// printf("a[%d]=%lld\n",i,a[i]);
//}
while (scanf("%d",&n),n)
{
printf("%lld\n",a[n]);
}
;
}
zoj1530 bfs的更多相关文章
- 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)
图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...
- 【BZOJ-1656】The Grove 树木 BFS + 射线法
1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 186 Solved: 118[Su ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- Sicily 1215: 脱离地牢(BFS)
这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而 ...
- Sicily 1048: Inverso(BFS)
题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作.可用BFS搜索解答,用vector储存每次的操作 #include<bits/stdc++. ...
- Sicily 1444: Prime Path(BFS)
题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...
- Sicily 1051: 魔板(BFS+排重)
相对1150题来说,这道题的N可能超过10,所以需要进行排重,即相同状态的魔板不要重复压倒队列里,这里我用map储存操作过的状态,也可以用康托编码来储存状态,这样时间缩短为0.03秒.关于康托展开可以 ...
- Sicily 1150: 简单魔板(BFS)
此题可以使用BFS进行解答,使用8位的十进制数来储存魔板的状态,用BFS进行搜索即可 #include <bits/stdc++.h> using namespace std; int o ...
随机推荐
- 快速开始使用Graph-tool - gt文件格式
gt文件格式 gt文件格式是一种简单的二进制格式,用来存储graph-tool的图实例,以一个紧凑和快速的方式,包括了库支持所有类型的属性映射. 它是graphml格式(基于文本)的另一种选择,gra ...
- 1.2G内存试玩RAMOS_XP
1.2G内存试玩RAMOS_XP1.为了防止做系统时出现意外,用Bootice把C盘MBR修改为Grub4dos,这样子系统如果失败,可以进入PE重做. 2.进入PE格式化C盘,格式化的时候勾选启用N ...
- Selenium Grid 运行报错 Exception thrown in Navigator.Start first time ->Error forwarding the new session Empty pool of VM for setup Capabilities
Selenium Grid 运行报错 : Exception thrown in Navigator.Start first time ->Error forwarding the new se ...
- RemoteWebDriver管理
直接贴代码: @Parameters({"BrowserType","NodeIP","NodePort"}) public void be ...
- Linux远程管理
若想要远程管理服务器,对于Windows系统,应该比较容易理解,通过window系统自带的远程桌面客户端即可登录远程服务器,从而实现在本地对远程服务器的管理.然而对于linux服务器来说这种方法就不行 ...
- phpMyAdmin中sql-parser组件的使用
版权声明:本文由陈苗原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/206 来源:腾云阁 https://www.qclou ...
- String的那一大堆事儿--1
perfTimeStr = perfTimeStr.replace(perfTimeStr.substring(0,4), "____"); perfTimeStr = perfT ...
- js鼠标拖拽
html <div id="box"> </div> css ;;} #box{width:200px;height:200px;background:cy ...
- hdu----(1950)Bridging signals(最长递增子序列 (LIS) )
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU----(3294)Girls' research(manacher)
Girls' research Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)T ...