資源簡介
實現(xiàn)了野人與傳教士過河問題的求解,并且簡單的實現(xiàn)了窗口動態(tài)演示過河過程

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
//定義過河狀態(tài)類
namespace?C_Y_H
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
???????????
????????}
???????List?list?=?new?List();
???????List?Left_c?=?new?List();
???????List?Left_y?=?new?List();
???????List?Right_c?=?new?List();
???????List?Right_y?=?new?List();
???????int??passNum?=?0;
???????int?Ly;
???????int?Ry;
???????int?Lc;
???????int?Rc;
?????????
??????
????????public?int?handle(RiverSide?boat)
????????{
????????????
????????????//是否達(dá)到目標(biāo)轉(zhuǎn)態(tài)
???????????if?(boat.getRight_c()?==?3?&&?boat.getRight_y()?==?3)?
????{?????????????
????passNum++;
????????????????textBox1.AppendText(“\n\n已為您找到第“?+?passNum?+?“條路徑!\n\n“);
????????????????textBox1.AppendText(“\n\n左傳“?+?“\t“?+?“左野“?+?“\t“?+?“右傳“?+?“\t“?+?“右野“?+?“\t“?+?“船\n\n“);
????????????????Ly?=?Left_y.Count;?????????
????????????????Ry?=?-1;
????????????????Lc?=?Left_c.Count;
????????????????Rc?=?-1;
???????????????if(passNum?!=?1)
???????????????{
???????????????????button9.Left?-=?300;
???????????????????button10.Left?-=?300;
???????????????????button11.Left?-=?300;
???????????????????button12.Left?-=?300;
???????????????????button13.Left?-=?300;
???????????????????button14.Left?-=?300;
???????????????????cc.Left?-=?300;
???????????????}
???????????????
????????????????for?(?int?i?=?0;?i?????????????????{
????????????????????System.Threading.Thread.Sleep(1000);??
????????????????????textBox1.AppendText(“?“?+?list[i].getLeft_c()?+?“\t?“?+?list[i].getLeft_y()?+?“\t?“?+?list[i].getRight_c()?+?“\t?“?+?list[i].getRight_y()?+?“\t“?+?list[i].getBoat_location()+“\n“);
????????????????????if?(list[i].getBoat_location()?==?1)
????????????????????{????
????????????????????????cc.Left?+=?300;???????????????????????????????????????
????????????????????????if?(Math.Abs(list[i+1].getLeft_c()-list[i].getLeft_c())?>=?1)
????????????????????????{?????????????????????????
????????????????????????????Lc--;
????????????????????????????Rc++;
????????????????????????????Left_c[Lc].Left?+=?300;
???????????????????????????
????????????????????????????if?(Math.Abs(list[i?+?1].getLeft_c()?-?list[i].getLeft_c())?>=?2)
????????????????????????????{
????????????????????????????????Lc--;
????????????????????????????????Rc++;
????????????????????????????????Left_c[Lc].Left?+=?300;
???????????????????????????????
????????????????????????????????if?(Math.Abs(list[i?+?1].getLeft_c()?-?list[i].getLeft_c())?==?3)
????????????????????????????????{
????????????????????????????????????Lc--;
????????????????????????????????????Rc++;
????????????????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-10-28?18:47??C_Y_H\
?????目錄???????????0??2018-11-17?16:46??C_Y_H\C_Y_H\
?????文件?????????187??2018-10-28?18:47??C_Y_H\C_Y_H\App.config
?????文件????????3790??2018-11-15?15:39??C_Y_H\C_Y_H\C_Y_H.csproj
?????文件????????9819??2018-11-16?21:14??C_Y_H\C_Y_H\Form1.Designer.cs
?????文件???????10714??2018-11-17?16:46??C_Y_H\C_Y_H\Form1.cs
?????文件???????49798??2018-11-16?21:14??C_Y_H\C_Y_H\Form1.resx
?????文件????????1852??2018-11-15?16:41??C_Y_H\C_Y_H\Program.cs
?????目錄???????????0??2018-10-28?18:47??C_Y_H\C_Y_H\Properties\
?????文件????????1334??2018-10-28?18:47??C_Y_H\C_Y_H\Properties\AssemblyInfo.cs
?????文件????????2862??2018-10-28?18:47??C_Y_H\C_Y_H\Properties\Resources.Designer.cs
?????文件????????5612??2018-10-28?18:47??C_Y_H\C_Y_H\Properties\Resources.resx
?????文件????????1092??2018-10-28?18:47??C_Y_H\C_Y_H\Properties\Settings.Designer.cs
?????文件?????????249??2018-10-28?18:47??C_Y_H\C_Y_H\Properties\Settings.settings
?????目錄???????????0??2018-10-28?18:47??C_Y_H\C_Y_H\bin\
?????目錄???????????0??2018-10-28?18:53??C_Y_H\C_Y_H\bin\Debug\
?????文件???????45568??2018-11-17?16:46??C_Y_H\C_Y_H\bin\Debug\C_Y_H.exe
?????文件?????????187??2018-10-28?18:47??C_Y_H\C_Y_H\bin\Debug\C_Y_H.exe.config
?????文件???????32256??2018-11-17?16:46??C_Y_H\C_Y_H\bin\Debug\C_Y_H.pdb
?????文件???????23168??2018-11-17?17:20??C_Y_H\C_Y_H\bin\Debug\C_Y_H.vshost.exe
?????文件?????????187??2018-10-28?18:47??C_Y_H\C_Y_H\bin\Debug\C_Y_H.vshost.exe.config
?????文件?????????490??2018-04-12?07:35??C_Y_H\C_Y_H\bin\Debug\C_Y_H.vshost.exe.manifest
?????目錄???????????0??2018-10-28?18:47??C_Y_H\C_Y_H\obj\
?????目錄???????????0??2018-11-17?16:46??C_Y_H\C_Y_H\obj\Debug\
?????文件???????30083??2018-11-16?21:14??C_Y_H\C_Y_H\obj\Debug\C_Y_H.Form1.resources
?????文件?????????180??2018-11-15?15:39??C_Y_H\C_Y_H\obj\Debug\C_Y_H.Properties.Resources.resources
?????文件?????????591??2018-11-17?17:20??C_Y_H\C_Y_H\obj\Debug\C_Y_H.csproj.FileListAbsolute.txt
?????文件?????????977??2018-11-16?21:14??C_Y_H\C_Y_H\obj\Debug\C_Y_H.csproj.GenerateResource.Cache
?????文件????????2211??2018-10-28?18:53??C_Y_H\C_Y_H\obj\Debug\C_Y_H.csprojResolveAssemblyReference.cache
?????文件???????45568??2018-11-17?16:46??C_Y_H\C_Y_H\obj\Debug\C_Y_H.exe
?????文件???????32256??2018-11-17?16:46??C_Y_H\C_Y_H\obj\Debug\C_Y_H.pdb
............此處省略8個文件信息
評論
共有 條評論