讲解:CMPS 12B-02、java、java、Piazza guidePython|Matlab

CMPS 12B-02, Fall 2017HW1: How to Place Your QueensDue: Oct 15, 2017 by 11:59pm All assignments must be submitted through git. Please look at the Piazza guideon submitting assignments. Please follow the naming conventions properly. Please look at the Piazza guideon the checking script. Run the checking script to make sure your files are namedcorrectly. You will get no credit if the checking script fails! Follow instructions, and carefully read through the input/output formats. Clearly acknowledge sources, and mention if you discussed the problems withother students or groups. In all cases, the course policy on collaboration applies, andyou should refrain from getting direct answers from anybody or any source. If indoubt, please ask the Instructor or TAs.1 Problem descriptionMain objective: Solve the n queens problems. You have to place n queens on an n ×n chessboard such that no two attack each other. Important: the chessboard should beindexed starting from 1, in standard (x, y) coordinates. Thus, (4, 3) refers to thesquare in the 4th column and 3rd row.We have a slight twist in this assignment. We will take as input the position ofone queen, and have to generate a solution with a queen in this position.Specifics: You should provide a Makefile. On running make, it should create“NQueens.jar”. You should run the jar with two command line arguments: the first isan input file, the second is the output file. For example, we would call the command: java -jar NQueens.jar in.txt solution.txtThe file in.txt will have inputs to the main program (as described below), andthe file solution.txt will have the desired solution.Each line of the input file corresponds to a different instance. Each line of theinput file will have three integers: the chessboard size, the column where the inputqueen is placed, and the row where the input queen is placed. For example, the filemay look like:7 3 24 1 1The first line means we have a 7 × 7 chessboard, with one queen placed at (3, 2).We wish to place 6 more queens so that none of the 7 queens attack any other. Thesecond line means we have a 4 × 4 chessboard, with one queen at (1, 1). We wish toplace 3 more queens without any attacks. So on and so forth.Output: On running the command, the following should be printed in the outputfile. For each line of the input file, there is a line in the output file with the placement 2of queens. If there is no solution to the problem, print “No solution” (with a newline at theend) If there is a solution, print the position of each queen as followed by the position for the next queen. The positionsshould be in increasing order of column, so first column first, second columnsecond, etc. Please follow this format exactly, so that the checking script worksfor you. The last character on the line will be a space, then followed by anewline. This format should make your code easier to write.For example, the output for the input described above could be:1 1 2 5 3 2 4 6 5 3 6 7 7 4No solutionObserve how “3 2” is part of the first solution, since we started with a queenthere. The solution is not unique, so your code might find some other placement. Onthe other hanCMPS 12B-02作业代写、代做java实验作业、java编程作业代写、代做Piazza guide作业 代写Pytd, a 4 × 4 chessboard with a queen at (1, 1) has no solution.Helper code: Under HW1 on Piazza, you will find a java file that prints out yoursolution on a chessboard (with queen positions) on to your console. This is extremelyhelpful in checking if your solution is correct. Compile and execute the java code onyour terminal using the commands below: javac PrintSolutionHelper.java java PrintSolutionHelper For each line in your output file that has a list of queens positions, the console willprint the chessboard with queens on then. (The code is actually pretty interesting!)Example commands and outputs: On Piazza, under HW1, you will find a filenamed HW1examples.zip. Download and unzip it. There are four files: test-input.txt, test-output.txt. If you run your program withinput file test-inputs.txt, the output file should be exactly the same astest-outputs.txt. This will be used by the checking script, and willneed to be in your solution folder. more-input.txt, more-output.txt. The former file has, ahem,more inputs, and the latter file has the outputs. For these instances, thecorresponding outputs might not be unique. So, your solution may be differentfrom what is given, since there can be numerous solutions3What to submit: Push all your java source files. There is no restriction onformat or how you name them. We only require that you have a makefile called“Makefile”. On running make, it should provide a jar file called “NQueens.jar”. Thechecking code uses the test files test-input.txt, test-output.txt.2 GradingYour code should terminate within 3 minutes for all runs (maximum chessboard sizewill be 14). You get no credit for a run that does not provide a proper output.1. (10 points) For a full solution as described above.2. (9 points) Only solves the problem when the input queen is in the first column.(This makes your recursive code a lot simpler to write.) When the input queenis not in the first column, just print “No solution”.3. (8 points) Only solves for chessboards at most 6 × 6. You can set up 12 nestedloops (6 for rows and 6 for columns) that simply try all possible placements of6 queens.4. (7 points) Only solves for chessboards at most 4 × 4.3 General RulesAll HWs and Labs must be done individually. All program source files you turn infor this and other assignments should begin with a comment block giving your nameand cruzid, a short description of its role in the project, the file name, and any specialinstructions for compiling and/or running it. Be sure to create a README file thatlists all the files being submitted (including README), along with any special notesto the grader.Please run the checking script as given on Piazza (under Resources?GeneralResources) to verify your file names. Piazza has a guide with instructions of runningit. If your solution/submission does not pass the checking script, you will get nocredit.You should use git commit –a –m msg and git push frequently (at least once persession). It is a great way to avoid losing your work. To actually submit yourassignment, while in the assignment directory (e.g. HW1 for this assignment) andafter having done git push of your latest work, type git log. 转自:http://ass.3daixie.com/2019013047523551.html

你可能感兴趣的:(讲解:CMPS 12B-02、java、java、Piazza guidePython|Matlab)