runxinzhi.com
首页
百度搜索
睡不着,随便写了下汉诺塔的解决方法。
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(
string
[] args)
{
int
times
=
new
HanoiTower(
3
).SolveTower();
Console.WriteLine(
"
一共需要{0}次
"
, times);
Console.ReadKey();
}
}
class
HanoiTower
{
private
int
plates;
public
HanoiTower(
int
plates)
{
this
.plates
=
plates;
}
public
int
SolveTower()
{
return
SolveTower(plates,
"
A
"
,
"
B
"
,
"
C
"
);
}
private
int
SolveTower(
int
plates,
string
a,
string
b,
string
c)
{
int
count
=
0
;
if
(plates
<=
0
)
throw
new
ArgumentOutOfRangeException(
"
plates
"
,
"
盘子数必须是大于0的整数
"
);
if
(plates
==
1
)
{
move(a, c);
return
1
;
}
count
+=
SolveTower(plates
-
1
, a, c, b);
count
+=
SolveTower(
1
, a, b, c);
count
+=
SolveTower(plates
-
1
, b, a, c);
return
count;
}
private
void
move(
string
a,
string
c)
{
Console.WriteLine(a
+
"
=>
"
+
c);
}
}
}
张旋(zxsoft)
如对本文有什么疑问,请在下面写下留言,谢谢!
相关阅读:
TypeError: translate() takes exactly one argument (2 given)
matlab为long term visual tracking数据集生成groundtruth.txt
Linux下为python3安装opencv
tensorflow全连接层降维
MDNet结果json文件转成long term visual tracking (oxuva)评估所需的csv文件的python脚本
no module named caffe
IIS短文件/文件夹泄露漏洞
点击劫持漏洞
WPF Combobox数据绑定 Binding
关于Win10安装vs2013简体中文语言包无法安装的问题
原文地址:https://www.cnblogs.com/zxsoft/p/1210400.html
最新文章
HTTP could not register URL http://+:****/WCFService/. Your process does not have access rights to this namespace
找出数组中是否有重复的数
IIS 7.0 HTTP 错误 404.3 Not Found解决办法
CSpider
C#字符串反转
MSMQ, WCF and IIS: Getting them to play nice (Part 3)[转]
安装和配置branchcache
数据库设计中的14个技巧
ASP.NET面试题(推荐_有答案)
petshop4.0设计说明
热门文章
VS2005 常用快捷键
常用正则表达式
ASP.NET 页生命周期概述
dojo学习笔记(一)-dojo.io.IO & dojo.io.BrowserIO
1小时教你学会正则表达式
C# 里面的 #region 是什么意思?
三层架构各层间的访问过程
IE7快捷键
C# 注释语法
windows 快捷键
Copyright © 2020-2023
润新知