前一阵子,一个在USC读书(master in AI)的哥们发来了他们一门课的作业题,让我帮着看看,我就试着写了一下,学习了学习,想看看美帝硅谷的CS学生都在学什么。
题目是这样的:
读入一个文件,which描述了一个N*N的矩阵,里面有些障碍物,然后要往里放皇后(国象的后),要使得他们之间互不能影响到。然后现在要求我们用三种方法解决这个问题:DFS、BFS、SA,分别是深搜、宽搜、模拟退火。作业的pdf文件很长,我节选了一下原文:
You will write a program that will take an input file that has an arrangement of trees and will output a new arrangement of lizards (and trees; as already mentioned, you can’t move the trees) such that no baby lizard can eat another one. You will be required to create a program that finds the solution. To find the solution you will use the following algorithms:
- Breadth-first search (BFS)
- Depth-first search (DFS)
- Simulated annealing (SA).
Input: The file input.txt in the current directory of your program will be formatted as follows:
First line: instruction of which algorithm to use: BFS, DFS or SA
Second line: strictly positive 32-bit integer n, the width and height of the square nursery