March 31 Tuesday Classroom Exercise: Pair development----to find a matrix of two-dimensional matrices the maximum value of the neutron matrix two

Source: Internet
Author: User

First, the topic requirements

1.1 Enter a two-dimensional shaping array with positive numbers in the array and a negative number. 1.2 Two-dimensional arrays end-to-end, like one end-to-end tape. 1.3 contiguous one or more integers in an array make up a sub-array, each of which has a and. 1.4 The maximum value of the and of all sub-arrays is evaluated. Requires a time complexity of O (n). Two, the pair requires 2.1 pair to complete the programming task. 2.2 One person is primarily responsible for program analysis, code programming. 2.3 A person is responsible for code review and Code test plans. 2.4 published a blog article about the process of cooperation between two people, and how to resolve the conflict (attached to the development of work photos). Third, the design process has been calculated in the two-dimensional array of the largest sub-matrix, this time the first phase of the matrix, we used the following method: And the first one-dimensional array to find the largest sub-array of the design idea is basically consistent: set the original matrix has n columns, the original matrix of the largest sub-matrix X1, and then move Make up a new matrix and then find the maximal sub-matrix X2 ... Move one column to the right, forming a new matrix and finding the maximum sub-matrix xn. Compares the size of the X1,X2......,XN and outputs the maximum value to the position. Iv. Source Code
#include <iostream> #include <time.h> #include <conio.h> #include <fstream>using namespace std ; ofstream out;void Randin (int rowintnum,int colintnum,int a[][100])//randomly generate a two-dimensional array {for (int. i=0;i<rowintnum;i++) {for ( int j=0;j<colintnum;j++) {a[i][j]=-(int) rand ()%201+100;cout<<a[i][j]<< ' \ t ';} Cout<<endl;}} int maxarray (int array[],int maxsize,int &location) {int max=array[0];//generate maximum value location=0;//maximum numeric subscript position initialize for (int i=0 ; i<maxsize;i++) {if (Max<array[i]) {max=array[i]; Location=i;}} return Max;} void Divanum (int a[][100],int rowintnum,int colintnum,int subrownum,int subcolnum,int evetsum[],int &Location,int times) {int sum[10000];//records the number of sub-matrices and int arraynum=0;//generates a sub-matrix of int count=0;//sub-matrix cumulative number for (int row=0;row< rowintnum-subrownum+1;row++) {for (int col=0;col<colintnum;col++)//Ask all sub-matrices {sum[arraynum]=0;for (int p=row;p< row+subrownum;p++)//Get sub-matrix and {for (int q=col;q<col+subcolnum;q++) {sum[arraynum]+=a[p][q%colintnum];}} arraynum++;//records the number of sub-matrices generated}}evetsum[times]=maxarRay (sum,arraynum,location);//Record the maximum number of sub-matrices in each generated sub-matrix}void Print (int row,int col, int array[][100]) {for (int i=0;i<row; i++) {for (int j=0;j<col;j++) {out<<array[i][j]<< ', ';} out<< ' \ n ';}} void Main () {Out.open ("Text.txt"), Srand ((unsigned) time (NULL)), int location[100];//record the position of each maximum sub-array int a[100][100], Rowintnum,colintnum;int subrownum,subcolnum;int max=0,loctimes=0;int evetsum[10000];int q=0;while (q==0) {cout< < "Please enter the number of lines:";cin>>rowintnum;out<<rowintnum<< ', ';cout<< "Please enter the number of columns:"; cin>>colintnum;o ut<<colintnum<< ', ' << ' \ n ';cout<< ' integer content ' <<endl; Randin (rowintnum,colintnum,a);//randomly generate rowintnum rows, colintnum array print (ROWINTNUM,COLINTNUM,A); for (subrownum=1; subrownum<=rowintnum; subrownum++) {for (subcolnum=1; subcolnum<=colintnum; subcolnum++) {divanum (a,rowintnum,colintnum,subrownum,subcolnum,evetsum,location[(SubRowNum-1) *RowIntNum+ SubColNum-1], (SubRowNum-1) *rowintnum+subcolnum-1);}} cout<< "Output maximum Matrix and" <<endl;max=maxarray (Evetsum, (SUBROWNUM-1) * (SubColNum-1), loctimes); Location[loctimes]++;cout<<max<<endl;out<<max;out.close ();cout<< "Continue testing (enter 0 continue)" <                <endl;cin>>q;system ("CLS"); System ("Pause");}}

  

Five, run six, knot to summarize this topic has been done many times, can say has been done rotten. But each time the subject requirements are different, the teacher always on the basis of the original problem has been expanded. Requirements are increasingly "excessive", from one-dimensional arrays to two-dimensional arrays, from "as long as the implementation" to the strict requirements of time complexity, from the maximum value to the maximum Subarray (matrix). But it is this gradual approach, I think let me learn a lot. And the previous exercise will provide a way to solve the problem behind the practice, in turn, the following exercises will deepen the understanding of the previous practice. The design method of this experiment, is according to the front of the problem-solving thinking very natural thought. Of course, our design method does not meet the 0 (n) requirement of the problem in time complexity. Our design method is not the best algorithm, there are a lot of repeated traversal, calculation, comparison. But in order to finish the homework we first put on the blog, the back of the idea of a good way to solve the problem will be in this blog to fill.

March 31 Tuesday Classroom Exercise: Pair development----to find a matrix of two-dimensional matrices the maximum value of the neutron matrix two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.