【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

预处理一下终点能到达哪些点。
暴力就好。
输出结果的时候,数字之间一个空格。。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
using namespace std; const int N = 30; int k;
int g[N+10][N+10];
bool can[N+10];
int a[N+10];
int vis[N+10],total; void dfs(int x){
if (can[x]) return;
can[x] = 1;
for (int i = 0;i <= N;i++)
if (g[x][i]) dfs(i);
} void dfs1(int x,int dep){
if (x==k){
total++;
cout <<1;
for (int i = 1;i < dep;i++){
cout <<' '<<a[i];
}
cout << endl;
return;
}
vis[x] = true;
if (!can[x]) return;
for (int i = 0;i <= N;i++)
if (g[x][i] && !vis[i]){
a[dep] = i;
dfs1(i,dep+1);
}
vis[x] = false;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int kase = 0;
while (cin >> k){
total = 0;
cout <<"CASE "<<++kase<<":"<<endl; memset(can,0,sizeof can);
memset(g,0,sizeof g);
int x,y;
while(cin >> x >> y){
if (x==0 && y==0) break;
g[x][y] = 1;
g[y][x] = 1;
}
dfs(k);
memset(vis,0,sizeof vis);
a[0] = 1;
dfs1(1,1);
cout <<"There are "<<total<<" routes from the firestation to streetcorner "<<k<<"."<<endl;
}
return 0;
}

【习题 7-1 UVA-208】Firetruck的更多相关文章

  1. Uva 208 - Firetruck

    [题目链接]http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&p ...

  2. UVa 208 - Firetruck 回溯+剪枝 数据

    题意:构造出一张图,给出一个点,字典序输出所有从1到该点的路径. 裸搜会超时的题目,其实题目的数据特地设计得让图稠密但起点和终点却不相连,所以直接搜索过去会超时. 只要判断下起点和终点能不能相连就行了 ...

  3. UVA - 208 Firetruck(消防车)(并查集+回溯)

    题意:输入着火点n,求结点1到结点n的所有路径,按字典序输出,要求结点不能重复经过. 分析:用并查集事先判断结点1是否可以到达结点k,否则会超时.dfs即可. #pragma comment(link ...

  4. UVA - 208 Firetruck(并查集+dfs)

    题目: 给出一个结点d和一个无向图中所有的边,按字典序输出这个无向图中所有从1到d的路径. 思路: 1.看到紫书上的提示,如果不预先判断结点1是否能直接到达结点d,上来就直接dfs搜索的话会超时,于是 ...

  5. UVa 208 Firetruck【回溯】

    题意:给出一个n个节点的无向图,以及某个节点k,按照字典序从小到大输出从节点1到节点k的所有路径 看的题解 http://blog.csdn.net/hcbbt/article/details/975 ...

  6. 习题7-1 uva 208(剪枝)

    题意:按最小字典序输出a到b 的所有路径. 思路:先处理出个点到目标点b的情况(是否能到达),搜索即可. 最开始我只判了a能否到b,然后给我的是WA,然后看了半天感觉思路没什么问题,然后把所有点都处理 ...

  7. 【UVa】208 Firetruck(dfs)

    题目 题目     分析 一开始不信lrj的话,没判联通,果然T了. 没必要全部跑一遍判,只需要判断一下有没有点与n联通,邻接表不太好判,但无向图可以转换成去判n与什么联通. 关于为什么要判,还是因为 ...

  8. UVa 208 消防车(dfs+剪枝)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. UVA 208 (DFS)

    题意:找出1到T的所有路径: 坑点:一开始以为是到终点,读错了题意,没测试第二个样例,结果WA了4遍,坑大了: #include <iostream> #include <cmath ...

  10. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

随机推荐

  1. 面试基础_03实现strcpy、strcat、strcmp、strlen

    实现代码例如以下: /************************************************************************* > File Name: ...

  2. 异步FIFO及verilog原码

    这几天看了Clifford E. Cummings的两篇大作<Simulation and Synthesis Techniques for Asynchronous FIFO Design&g ...

  3. javascript 提交弹窗

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 1.cocos_helloworld

    在class HelloWorld : public cocos2d::Layer中添加函数 void menuclose(cocos2d::Ref *psender); 实现: void Hello ...

  5. POJ 3626 BFS

    思路:easy BFS //By SiriusRen #include <queue> #include <cstdio> #include <algorithm> ...

  6. zip-tar

    1.zip 制作压缩文件 (1)格式:zip 压缩文件名 文件1 文件2... zip文件不能用cat查看 (2)选项: -r:用来压缩目录 2.unzip 解压缩文件 (1)格式:unzip 压缩文 ...

  7. PHP定时执行任务

    ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去 $int ...

  8. Mysql学习总结(7)——MySql索引原理与使用大全

    一.索引介绍 索引是对数据库表中一列或多列的值进行排序的一种结构.在关系数据库中,索引是一种与表有关的数据库结构,它可以使对应于表的SQL语句执行得更快.索引的作用相当于图书的目录,可以根据目录中的页 ...

  9. 洛谷 P1013 进制位

    P1013 进制位 题目描述 著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字. 例如: + L K V E L L K V E K K V E KL V V E ...

  10. LeetCode 223 Rectangle Area(矩形面积)

    翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...