服务承诺





51Due提供Essay,Paper,Report,Assignment等学科作业的代写与辅导,同时涵盖Personal Statement,转学申请等留学文书代写。




私人订制你的未来职场 世界名企,高端行业岗位等 在新的起点上实现更高水平的发展




美国大学Algorithm算法作业怎么写,留学生Algorithm作业写作技巧辅导
2017-03-01 来源: 51Due教员组 类别: 写作技巧
Algorithm是什么意思?Algorithm其实就是算法、运算法则的意思,我们在利用C++完成编程作业或解决公式问题时也会常常接触到,那么当美国大学老师布置这种Algorithm算法作业时我们应该怎么写呢?作为Algorithm算法作业代写经验丰富的我,今天就来辅导和指点各位这类的Algorithm作业应该怎么写以及在写作中都有哪些技巧可以使用,一起来看看吧。
java maze solver
Important: This is an individual assignment. Please do not collaborate.
No late assignment will be accepted.
Make sure that you write every line of your code. Using code written by someone else will be considered a violation of the academic integrity and will result in a report to the Dean’s office.
Minimal Submitted Files
You are required, but not limited, to turn in the following source files:
Assignment11.java (You do not need to modify this file.)
MazeSolver.java — complete this file.
Position.java (You do not need to modify this file)
Requirements to get full credits in Documentation
The assignment number, your name, StudentID, Lecture number, and a description of each class/file need to be included at the top of each file/class (in this assignment, you might have only one file/class, but in future there will be more than one file.)
A description of each method is also needed.
Some additional comments inside of methods (especially for a “main” method) to explain code that are hard to follow should be written. You can look at Java programs in the text book to see how comments are added to programs.
New Skills to be Applied
In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:
Stacks
Program Description
Assignment #11 will be the construction of a program that solves a maze problem.
Your program needs to find a way to go from the upper right corner (where you see ‘>’ character) to the lower left corner (where you see ‘<‘ character). If you see a dot ‘.’, that mean that slot is available to go through, but if you see a pound sign ‘#’, that means that there is an obstacle and you cannot go through there.
Whenever you go though, you need to change the character at that position to ‘.’ to ‘x’. It is possible that one path that you try might lead to a dead end. In that case, you need to backtrack to try another path. The position you decide not to include in your solution path should now be changed to ‘O’ to record that you have already tried that position. Therefore in this assignment, you will store a successful path (a sequence of positions) in a stack. Whenever you proceed to a new position, you need to push that position information onto the stack. When you decide to back track, you need to pop the position that you are not using as part of a solution path.
In this way, when you reach the goal, the stack should contain a sequence of positions that you took from the starting point to the goal. Also, if one sees the result maze, he/she can also track the solution path by following Xs that you recorded in the maze.
Here is an example. Suppose that you are given the following maze:
.........>
#....#...#
#....##..#
....#.##..
#..#......
.###.#..#.
..#.##....
#....#.##.
.##..#.###
<.#.###...
Then a solution is:
.........>
#....#..x#
#....##.x#
....#.##x.
#..#.x..x.
.###x#xx#.
..#x##xx..
#xxxO#x##.
x##xO#O###
<.#O###OOO
The sequence of Xs shows the solution path. Note that the positions with an O are already visited, but reached a dead end, so it was removed from the solution path.
Instruction:
You will be given a maze with the size of 10 rows and 10 columns. You need to start from the upper right corner (row = 0, column = 9), and check which adjacent position is available (not ‘#’ or ‘O’ or out of bounds). When you do this checking, you MUST check in the following order:
First check the location below the current position.
If that position is not available to proceed, then check all other 7 positions around the current position in clockwise direction.
Therefore, you always check in the order of ‘down’, ‘down left’, ‘left’, ‘up left’, ‘up’, ‘up right’, ‘right’, and ‘down right’.
For instance, if your current position is at (i,j) row = i and column = j, then you need to check (i+1,j) position first.
If the position is not available to proceed, then you check (i+1,j-1), (i,j-1), (i-1,j-1), (i-1,j), (i-1,j+1), (i,j+1), (i+1,j+1).
Position class
This class pairs a row number (int) and a column number (int). Its constructor takes a row number and a column number, and it has accessor methods for row and column, getRow() and getColumn().
It also has a face which keeps track of which direction to go from that position so that it can show a solution at the end. It has an accessor method and a mutator method of face and also toString method.
Face values of 0,1,2,3,4,5,6, and 7 represent the direction of ‘down’, ‘down left’, ‘left’, ‘up left’, ‘up’, ‘up right’, ‘right’, and ‘down right’ respectively.
This class is given by the instructor.
Assignment11 class
This class displays a menu for the Maze Problem. If a user enters “E”, then it asks to enter an initial maze configuration, then it will display a result for the problem. This class is given by the instructor.
MazeSolver class
The MazeSolver class contains a constructor to set up an initial maze configuration.
It also contains methods to print out a result maze as well as a solution path. These methods are given by the instructor.
You need to complete the following findSolution method based on its pseudo-code.
public boolean findSolution()
You need to write the findSolution method that determines whether there is a solution to the Maze problem. It should return true if a solution is found, false otherwise. If a solution is found, then the program should display the result maze with Xs and Ox. Your program should display intermediate steps by printing “Trying the position of row 2 and column 7”.
Each time a choice is made, the choice is pushed onto a stack that already contains all the previously made choices. The following is the pseudo-code for this. It assumes that for a 10-by-10 maze, rows vary from 0 to 9 and columns vary from 0 to 9. You need to start with (0,9), then try to find an adjacent position to move to. (In this case, trying to go to (1,9).If this does not work, then you need to try to go to (1,8), etc.
boolean success = false;
boolean finish = false;
Push (0,9) — row 0 and column 9 information onto the stack indicating the first choice is (0,9).
while (finish = = false && stackSoln.isEmpty( ) = = false)
{
Check the most recent position from the stack, and check which of eight adjacent positions to move from the recent position,
in the order of ‘down’, ‘down left’, ‘left’, ‘up left’, ‘up’, ‘up right’, ‘right’, and ‘down right’.
This part requires another nested loop to repeat at most 8 times to check eight adjacent positions.
If such adjacent position is not outside of the maze range,
row and column being greater than or equals to 0 or less than or equals to 9, and being able to move into
(it needs to contain ‘x’ or ‘<‘ the goal position),
then we found a position to move to.
As soon as we find a position to move to, save its direction to ‘face’ variable and get out of the loop
(‘face’ can contain 0,1,2,3,4,5,6, and 7 representing the direction of
‘down’, ‘down left’, ‘left’, ‘up left’, ‘up’, ‘up right’, ‘right’, and ‘down right’ respectively).
If the found adjacent position to move to is the goal position (contains ‘<‘),
then we found a solution path, and set ‘success’ to true and ‘finish’ to true.
Also set the face of the current position to ‘face’ value obtained by the above loop.
If the found adjacent position to move to is not the goal position,
then push the object of such adjacent position onto the stack, and set the adjacent position to ‘x’.
Also set the face of the current position to ‘face’ value obtained by the above loop.
If we cannot find any adjacent position to move to, then set the current position to ‘O’, if it was ‘x’.
Then pop the solution stack, which means not including this position in the solution path.
If the stack is empty at this time, then there is no other place to back track, thus the maze does not have a solution.
Set ‘success’ to false and ‘finish’ to true.
} //end of while loop
return success;
Requirements:
You need to implement this method using an object of the Stack class in java.util package. This stack will contain objects of the Position class.
Input
The following files are the test cases that will be used as input for your program (Right-click and use “Save As”):
Test Case #1
Test Case #2
Test Case #3
Test Case #4
Output
The following files are the expected outputs of the corresponding input files from the previous section (Right-click and use “Save As”):
Test Case #1
Test Case #2
Test Case #3
Test Case #4
OR you can download all files at once:
看完了以上对于美国留学生Algorithm算法作业的讲解与辅导后,各位留学生们是否也学会了该如何去写作这种类型的算法作业了吧,想要写好这种类型的算法作业最重要的一点就是理清自己运算的思路,只有在思路清晰后我们才能够清楚使用什么样的算法元素才能够达到我们想要的效果。
51due教育引领海外留学的风向标,打造最好的留学教育品牌,我们为自己的品牌代言,不负留学生的期待。提供全方位的服务,包括留学生作业代写、paper代写、essay代写、assignment代写服务。
更多关于写作技巧的内容,点开主页栏目 即可快速获取美国作业代写帮助,有论文代写需求,咨询24小时客服QQ:800020041,为您详细解答。-xz
