First, the minimum product (basic type) "This topic needs to read carefully, the content is large, just at the beginning, because the practice system on the input and output format has problems, did not understand, finally in the MIKCU blog saw the correct format, reference code, and finally get the correct results. In order to minimize the results, you can sort the two groups of numbers first, and then reverse the set of data, reverse the two sets of data, the largest and the smallest, the last to obtain and the smallest! "

The problem is described to two groups of numbers, each n.

Adjust the order of the numbers in each group so that the two sets of data are multiplied by the same subscript elements, and then added and minimized. Requires the program to output this minimum value.

For example, two groups of numbers are: 1 3-5 and-2 4 1

Then the minimum value corresponding to the sum of products should be:

(-5) * 4 + 3 * (-2) + 1 * 1 =-25 input formatThe first line, a number t, represents the number of data groups. After each set of data, first read into an n, the next two rows per row n number, the absolute value of each number is less than or equal to 1000.

n<=8,t<=1000 output Format A number represents the answer. Sample input 2//two set of data 3/per line three number 1 3-5-2 4 1 5//Line five number 1 2 3 451 0 1) 0 1Sample Output-25 6

1 Importjava.util.Arrays;2 ImportJava.util.Scanner;3 4 Public classMain {5 StaticScanner Mscanner;6 7 Public Static voidMain (string[] args) {8 9Mscanner =NewScanner (system.in);Ten intn =mscanner.nextint (); One A int[] sum =New int[n]; - for(inti = 0; I < n; i++) { -Sum[i] =getmaxsum (); the } - for(inti = 0; I < n; i++) { - System.out.println (Sum[i]); - } + - } + A Public Static intgetmaxsum () { at intCount =mscanner.nextint (); - int[] Array1 =New int[Count]; - int[] Array2 =New int[Count]; - for(inti = 0; I < count; i++) { -Array1[i] =mscanner.nextint (); - } in for(intj = 0; J < Count; J + +) { -ARRAY2[J] =mscanner.nextint (); to }Arrays.sort (array1); Arrays.sort (array2); array2 = Getreverse (array2) ; * $ intsum = 0;Panax Notoginseng for(inti = 0; I < count; i++) { -sum = array1[i] * Array2[i] +sum; the } + A returnsum; the } + - Public Static int[] Getreverse (int[] arr) { $ intLength =arr.length; $ int[] Array =New int[length]; - for(inti = 0; i < arr.length; i++) { -Array[i] = arr[length-1]; thelength--; - }Wuyi the returnArray; - } Wu -}

Second, Torry confusion (basic type) "The key to this problem is to save the prime number of the product to 50000 of the results of the surplus, if the product is retained, it will cause data too large, memory overflow and other problems ..."

Problem description Torry from childhood love mathematics. One day, the teacher told him, like 2, 3, 5, 7 ... Such numbers are called prime numbers. Torry suddenly thought of a problem, the first 10, 100, 1000, 10000 ... What is the product of a prime number? He told the teacher the question. The teacher was stunned and couldn't answer it. So Torry turned to the programmer, and asked you to calculate the product of the first n prime numbers. However, considering that you are only in touch with programming soon, Torry as long as you figure out the value of 50000 on the modulo. The input format contains only a positive integer n, where n<=100000. The output format outputs a row, which is the value of the product modulo 50000 of the first n prime numbers. Example input 1 Sample output 2

1 ImportJava.util.Scanner;2 3 Public classMain {4 5 Public Static voidMain (string[] args) {6 7Scanner Mscanner =NewScanner (system.in);8 intn =mscanner.nextint ();9 inti = 0;Ten intStart = 2; One intSS = 1; A while(i<N) { - if(Issushu (start)) { -SS = (Ss*start)%50000; thei++; - } -start++; - } + SYSTEM.OUT.PRINTLN (ss); - } + A Public Static BooleanIssushu (intm) { at for(inti = 2; I*i <= m; i++) { - if(m%i==0) { - return false; - } - } - return true; in - } to +}

Searching for the maximum value in the array "This problem can not use the sort () function, because to output its subscript, so here is a loop, but I just think of a method, is to use the sort function to the original array of the backup order, and then get the maximum value, the original array using GetIndex () method to get its index, this method should be feasible. 】

The problem description is for the given integer array a[], looking for the maximum value and returning the subscript. Input format integer array a[], the number of array elements is less than 1 equals 100. The output data is divided into two rows: the first line has only one number, which indicates the number of elements in the array, and the elements of the second behavior array. Output format output maximum value, and its subscript sample input 3 3 2 1 sample output 3 0

1 ImportJava.util.Scanner;2 3 Public classMain {4 5 Public Static voidMain (string[] args) {6 7Scanner Mscanner =NewScanner (system.in);8 intn =mscanner.nextint ();9 int[] Arrays =New int[n];Ten for(inti = 0; I < n; i++) { OneArrays[i] =mscanner.nextint (); A } - - intMax =Integer.min_value; the intMaxindex =0; - for(inti = 0; i < arrays.length; i++) { - if(Arrays[i] >max) { -Max =Arrays[i]; +Maxindex =i; - } + } A atSystem.out.println (max+ "" +maxindex); - - } - -}

Iv. Correlation Matrix ""

The problem description has a forward graph of n nodes m edges, please output his correlation matrix. Input format the first line two integers n, m, indicating the number of nodes and edges in the graph. n<=100,m<=1000.

Next m line, two integers a, b for each line, indicates that there are (b) edges in the diagram.

Note that the image may contain a heavy edge, but there is no self-loop. Output format output the graph's correlation matrix, and be careful not to change the order of edges and nodes. Sample Input 5 9

1 2

3 1

1 5

2 5

2 3

2 3

3 2

4 3

5 4 Sample Output 1-1 1 0 0 0 0 0 0

-1 0 0 1 1 1-1 0 0

0 1 0 0-1-1 1-1 0

0 0 0 0 0 0 0 1-1

0 0-1-1 0 0 0 0 1

1 ImportJava.util.Scanner;2 3 Public classmain{4 5 Public Static voidMain (string[] args) {6 7Scanner Mscanner =NewScanner (system.in);8 intn = mscanner.nextint ();//Dian9 intm = Mscanner.nextint ();//BianTen int[] Array =New int[n][m]; One intx, y; A for(inti = 0; I < m; i++) { -x =mscanner.nextint (); -y =mscanner.nextint (); theArray[x-1][i] =1; -Array[y-1][i] =-1; - } - for(inti = 0; I < n; i++) { + for(intj = 0; J < M; J + +) { -System.out.print (array[i][j]+ ""); + } A System.out.println (); at } - - } - -}

**Note: This article is original, starting in the blog park, reproduced please indicate the source.**

Blue Bridge Cup algorithm training < two;