HDU 4337 King Arthur's Knights
题意:图中有N个点,每个点至少和其他(N+1)/2个点连接,问能否找到一个有N个点的环(即不存在重复的点,N个点都在内)。
分析:数据量小,直接暴力深搜,起点直接设为点1(一定能找到环 或者 环本身不存在)。
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <climits>//形如INT_MAX一类的
#define MAX 200
#define INF 0x7FFFFFFF
# define eps 1e-5
//#pragma comment(linker, "/STACK:36777216") ///传说中的外挂
using namespace std;int map[MAX][MAX];
int path[MAX];
int vis[MAX];
int n,m,ok;void init()
{memset(vis,0,sizeof(vis));memset(path,0,sizeof(path));
}void dfs(int u0,int v,int cur)
{path[cur] = v;if(cur == n && map[u0][v]){ok = 1;return ;}for(int i=1; i<=n; i++){if(vis[i] == 0 && map[v][i]){vis[i] = 1;dfs(u0,i,cur+1);vis[i] = 0 ;}if(ok == 1)return ;}
}int main()
{while(cin >> n >> m){int a,b;memset(map,0,sizeof(map));for(int i=0; i<m; i++){scanf("%d%d",&a,&b);map[a][b] = 1;map[b][a] = 1;}ok = 0;init();vis[1] = 1;dfs(1,1,1);if(ok == 1){for(int i=1; i<n; i++){cout << path[i]<< ' ';}cout << path[n] << endl;}elsecout << "no solution" << endl;}return 0;
}
HDU 4337 King Arthur's Knights相关推荐
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDU - 5640 -King's Cake
It is the king's birthday before the military parade . The ministers prepared a rectangle cake of si ...
- HDU 5643 King's Game 【约瑟夫环】
题意: 变形的约瑟夫环,最初为每个人编号1到n,第i次删去报号为i的人,然后从它的下一个人开始重新从1开始报号,问最终剩下第几号人? 分析: 首先看一下裸的约瑟夫环问题: 共n个人,从1开始报数,报到 ...
- HDU - 5643 King's Game (约瑟夫环变式)
题目大意: n个人围成一个环坐着,编号从1到n,从第一个人开始报数,第一轮报到1的人出列:第二轮报到2的人出列......第n-1轮报到n-1的人出列,问最后剩下的人的编号是多少 题解: ①首先本题的 ...
- hdu 4337——poj 2438(哈密尔顿回路求解模板)
转:http://imlazy.ycool.com/post.2072698.html Dirac 定理:设一个无向图中有 N 个节点,若所有节点的度数都大于等于 N/2,则汉密尔顿回路一定存在.注意 ...
- 【POJ - 2942】Knights of the Round Table(点双连通分量,二分图判断奇环奇圈)
题干: Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in dist ...
- 如果圆桌骑士有特殊情况(Knights of the Round Table)
题目描述 Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in dis ...
- 【EXLIBRIS】随笔记 001
随 笔 记 <一> 从"我"谈起:I,古英语里写作ic,德语的I是Ich,非常相似.古英语的数里有一种现在已经消失了的双数:wit,git,只存在于第1.2人称里:另外 ...
- table 多行 宽度不一致_“table”除了桌子,你还知道一些别的意思吗?
就比如"nine-nine table" 这可是小学一年级必须要掌握的知识 实际上,nine-nine table是九九乘法表,乘法表可以用times table表示,书面用语是m ...
最新文章
- 2015 Multi-University Training Contest 1 - 10010 Y sequence
- 家庭安全摄像头:应选择本地还是云端存储?
- 十、深入Java字符串(下篇)
- glibc的头文件 linux_求助,编译glibc头文件时出错
- 编译原理第一次上机作业感想
- android google map 标记,android google map添加标记和TipView
- 如果工作时间固定,居住城市是可以实现的
- Android之PreferenceActivity (转载)
- 【Pytorch】谈谈我在PyTorch踩过的12坑
- PE文件格式详解(一)
- Johnson算法PlantSimulation解决两机器多作业排版问题
- C/C++ 内存对齐原则及作用
- warning: control reaches end of non-void function [-Wreturn-type]
- 京东VC后台自动批量上传主图 大聪明自动传主图 c# selenium网页自动化传图
- Python爬虫:博客被抄袭了还不知道?快来查查
- 百度网盘搜索工具汇总
- 数据库与MPP数仓(十四):招标采购系统的数据仓库构建
- ChatGPT会对未来5年的NLP算法从业者带来怎样的冲击?
- 现在学习软件测试好找工作吗
- 游匣G15新机开箱测评,果然顶配是真香
热门文章
- 计算机技术薄弱对我省影响,计算机技术在贵州省西南地区的运用前景.docx
- 第14题 计算机网络故障排除的第二步是,计算机网络故障诊断与排除第1章网络故障和网络诊断测试工具(习题)(ok)...
- 绝对定向 c++_【007】Linux重定向、管道符及环境变量(看这一文就够了)
- python 3.8.0安卓_Python 3.8.0 正式版发布,新特性初体验
- androidx86 9.0下载_Surface pro 安装 android x86/chrome OS
- CSS基础——CSS 三大特性【学习笔记】
- 如果不当程序员,我可以生活的更好么?
- 计算机组装与维护课程教学内容,《计算机组装与维护》课程教学计划
- qt读oracle时间戳,QT解析时间戳与微秒级精度
- 工作了五年才明白的道理,这些原来我一开始就做错了