Directory
1 Calculation
2 squares of fill
3 Four Square and
1 calculation
Formula B +---+-------= ten C GHI (see figure 1.jpg If there is a problem) in this equation a~i representsthe number of 1~ 9, Different letters represent different numbers. For example:6+8/3+952/714 is a solution,5+3/1+972/486 is another solution. How many solutions are there in this equation? Note: Your submission should be an integer, do not fill in any superfluous content or descriptive text. (in the case of division, it is important to note that if the title is not pre-stated, the denominator is eliminated first, multiplication is performed, so that the floating-point error can be eliminated) in
Public classMain { Public Static intCount = 0; Public voidSwapint[] A,intAintb) {inttemp =A[a]; A[a]=A[b]; A[B]=temp; } Public voidDfsint[] A,intStep) { if(Step = =a.length) {if(check (A)) Count++; return; } Else { for(inti = Step;i < a.length;i++) {Swap (A, I, step); DFS (A, step+ 1); Swap (A, I, step); } } return; } Public BooleanCheckint[] A) {intA1 = a[0] * a[2] * (a[6]*100 + a[7]*10 + a[8]); intA2 = a[1] * (a[6]*100 + a[7]*10 + a[8]); intA3 = (a[3]*100 + a[4]*10 + a[5]) * a[2]; if(A1 + a2 + a3 = = Ten * a[2] * (a[6]*100 + a[7]*10 + a[8])) return true; return false; } Public Static voidMain (string[] args) {main test=NewMain (); int[] A = {1,2,3,4,5,6,7,8,9}; Test.dfs (A,0); System.out.println (count); }}
2 squares of fill
Check the box to fill in the following 10 squares +--+--+--+ | | | | +--+--+--+--+| | | | | +--+--+--+--+| | | | +--+--+--+(if there is a problem, you can also refer to "Figure 1.jpg") to fill in 0~9 numbers. Requirement: Consecutive two digits cannot be contiguous. How many possible filling schemes are there (around, up, down, diagonal)? Please complete an integer representing the number of scenarios. Note: You should submit an integer, do not fill in any superfluous content or descriptive text. 1580
Public classMain { Public Static intCount = 0; Public voidSwapint[] A,intAintb) {inttemp =A[a]; A[a]=A[b]; A[B]=temp; } Public voidDfsint[] A,intStep) { if(Step = =a.length) {if(check (A)) Count++; return; } Else { for(inti = Step;i < a.length;i++) {Swap (A, I, step); DFS (A, step+ 1); Swap (A, I, step); } } return; } Public BooleanCheckint[] A) {if(Math.Abs (a[0]-a[3])! = 1 && math.abs (a[0]-a[1])! = 1 && math.abs (a[0]-a[4])! = 1 && math.abs (a[0] -A[5])! = 1) { if(Math.Abs (a[1]-a[4])! = 1 && math.abs (a[1]-a[5])! = 1 && math.abs (a[1]-a[2])! = 1 && math.abs (a[1] -A[6])! = 1) { if(Math.Abs (a[2]-a[5])! = 1 && math.abs (a[2]-a[6])! = 1) { if(Math.Abs (a[3]-a[4])! = 1 && math.abs (a[3]-a[7])! = 1 && math.abs (a[3]-a[8])! = 1) { if(Math.Abs (a[4]-a[5])! = 1 && math.abs (a[4]-a[7])! = 1 && math.abs (a[4]-a[8])! = 1 && math.abs (a[4] -A[9])! = 1) { if(Math.Abs (a[5]-a[8])! = 1 && math.abs (a[5]-a[9])! = 1 && math.abs (a[5]-a[6])! = 1) { if(Math.Abs (a[6]-a[9])! = 1 && math.abs (a[7]-a[8])! = 1) { if(Math.Abs (a[8]-a[9])! = 1) return true; } } } } } } } return false; } Public Static voidMain (string[] args) {main test=NewMain (); int[] A = {0,1,2,3,4,5,6,7,8,9}; Test.dfs (A,0); System.out.println (count); }}
3 Four square and
Four squared sum four squared sum theorem, also known as Lagrange's theorem: Each positive integer can be expressed as the sum of the squares of up to 4 positive integers. If 0 is included, it can be represented as a sum of 4 squares. For example:5 = 0^2 + 0^2 + 1^2 + 2^27 = 1^2 + 1^2 + 1^2 + 2^2(^the symbol denotes the meaning of a exponentiation) for a given positive integer, there may be multiple representations of the sum of squares. Ask you to sort 4 numbers:0 <= a <= b <= c <=D and for all possible representations by A,B,C,D as the Union primary key in ascending order, and finally output the first notation program input as a positive integer n (n<5000000requires output of 4 non-negative integers, sorted from small to large, separated by spaces for example, enter:5The program should output:0 0 1 2again, for example, enter:12The program should output:0 2 2 2again, for example, enter:773535The program should output:1 1 267 838Resource contract: Peak memory consumption (with virtual machines)<256MCPU Consumption<3000ms Please strictly according to the requirements of the output, do not be superfluous to print similar: "Please enter ..." Redundant content. All the code is placed in the same source file, after debugging passed, the copy is submitted to the source. Note: Do not use the package statement. Do not use jdk1.7 and the features of the above version. Note: The name of the main class must be: main, otherwise it will be treated as invalid code.
ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); intN =In.nextint (); intLen = (int) math.sqrt (N); for(intA = 0;a <= len;a++) { for(intb = A;b <= len;b++) { for(intc = B;c <= len;c++) { for(intD = c;d <= len;d++) { inttemp = a*a + b*b + c*c + d*D; if(temp = =N) {System.out.println (a+ "" +b+ "" +c+ "" +d); return; } } } } } }}
Algorithm note _123: Blue Bridge Cup seventh session (Java language Group B part exercises) questions