HDU2181(KB2-C)
哈密顿绕行世界问题
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3890 Accepted Submission(s): 2358
Problem Description
Input
Output
Sample Input
Sample Output
Author
Source
//2017-03-01
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int M[][], ans[], vis[], m, kase; void dfs(int city, int step)
{
if(step == && city == m){
cout<<++kase<<": ";
for(int i = ; i < ; i++)
cout<<ans[i]<<" ";
cout<<m<<endl;
return;
}
ans[step] = city;
for(int i = ; i < ; i++)
{
if(!vis[M[city][i]])
{
vis[M[city][i]] = ;
dfs(M[city][i], step+);
vis[M[city][i]] = ;
}
}
} int main()
{
while(cin>>M[][]>>M[][]>>M[][])
{
sort(M[], M[]+);
for(int i = ; i <= ; i++)
{
cin>>M[i][]>>M[i][]>>M[i][];
sort(M[i], M[i]+);
}
while(cin>>m && m)
{
memset(vis, , sizeof(vis));
kase = ;
dfs(m, );
}
} return ;
}
HDU2181(KB2-C)的更多相关文章
- HDU2181:哈密顿绕行世界问题(DFS)
哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- hdu2181 简单搜索
题意: 一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市. Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第 ...
- 哈密顿绕行世界问题(hdu2181)
哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Hdu2181 哈密顿绕行世界问题 2017-01-18 14:46 45人阅读 评论(0) 收藏
哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- 哈密顿绕行世界问题---hdu2181(全排列问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 题意很容易理解,dfs就可以了 #include <iostream> #inclu ...
- HDU2181 哈密顿绕行世界问题
解题思路:哈密顿环游世界问题.一道简单的题目,用回溯. #include<cstdio> #include<cstring> #include<algorithm> ...
- HDU2181(基础dfs)
哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU2181 哈密顿绕行世界问题 —— DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) ...
- 哈密顿绕行世界问题 HDU2181
题目大意都比较简单,用vector存一下图,然后爆搜就可以了. #include<bits/stdc++.h> using namespace std; ; vector<]; bo ...
随机推荐
- 使用VS Code开发.Net Core 2.0 MVC Web应用程序教程之一
好吧,现在我们假设你已经安装好了VS Code开发工具..Net Core 2.0预览版的SDK dotnet-sdk-2.0.0(注意自己的操作系统),并且已经为VS Code安装好了C#扩展(在V ...
- 用node.js写一个简单爬虫,并将数据导出为 excel 文件
引子 最近折腾node,最开始像无头苍蝇一样到处找资料,然而多数没什么卵用,都在瞎比比.在一阵瞎搞后,我来分享一下初步学习node的三个过程: 1 撸一遍NODE入门,对其有个基本的了解: 2 撸一遍 ...
- git 查看提交记录
查看提交的内容 -p 选项,同时在 - 后加数字限制一下数目 git log -p -2. commit 500eeadd71a21f1166803e12a792bfa86f4ca784 (HEAD ...
- android 代码实现back键功能
方案一,简单但响应慢: doExec("input keyevent 4"); public String doExec(String cmd) { String s = &quo ...
- centos7无法上网问题
在虚拟机VM中安装了centos7,无法上网,在同一个虚拟机里,也安装了Ubuntu是可以上网的,不知道咋回事,所以上网查了资料博客,现总结如下. 一.首先打开虚拟的设置,可以看到虚拟机网络的设置默认 ...
- day 41 数据库初学习
前情提要: 数据库初识别 一:数据库的介绍 https://github.com/Endless-Clould/homework/blob/master/student_system.sql 数据再这 ...
- UIDevice currentDevice model possible values
NOTE: The below code may not contain all device's string, I'm with other guys are maintaining the sa ...
- J07-Java IO流总结七 《 InputStreamReader和OutputStreamWriter 》
前面在介绍FileReader和FileWriter的时候有说到,FileReader的读取字符功能,以及FileWriter的写出字符的功能,都不是它们自己实现的,而是,它们分别继承了InputSt ...
- RabbitMQ和Kafka对比以及场景使用说明
我目前的项目最后使用的是RabbitMQ,这里依然是结合网上大神们的优秀博客,对kafka和rabbitmq进行简单的比对.最后附上参考博客. 1.架构模型 rabbitmq RabbitMQ遵循AM ...
- Intellij-插件安装-安装CodeGenerator插件并且添加Builder模板
Intellij IDEA 2018.1.2版本 CodeGenerator插件地址:https://github.com/lotabout/CodeGenerator/releases 步骤一:安装 ...