Today, I looked at NetEase's latest school recruit written questions:
Small easy to have a positive integer sequence of length N = {A[1], a[2], a[3] ..., A[n]}. Dr. Niu gave a little difficulty:
The logarithmic column A is rearranged so that the sequence a satisfies all A[i] * a[i + 1] (1≤i≤n-1) is a multiple of 4.
Small easy now need to determine whether a sequence can be re-ordered to meet the requirements of Dr. Niu.
The code is as follows:
1 ImportJava.util.Scanner;2 3 /**4 * Created by JY on 2017/9/9.5 */6 Public classFourbeishu {7 Public Static BooleanIsRequired (intLengthint[] a) {8 intJishu = 0;9 intFour = 0;Ten intOushu = 0; One for(inti = 0; I <= length-1; i++) { A //does not meet the requirements - if(A[i] <= 0) { - return false; the } - //odd number of numbers - if(A[i]% 2 = = 1) { -jishu++; + } - //just two times the number of numbers + if(A[i]% 2 = = 0 && a[i]% 4! = 0) { Aoushu++; at } - //multiples of 4 - if(A[i]% 4 = = 0) { -four++; - - } in } - //A multiple of 4 is greater than half-1 of the array's length, which can satisfy a[i] and a[i+1] must have a multiple of 4, thus missing all even-numbered cases, such as 2 2 6 to if(Four >= length-four-1) { + return true; - } the //The number of multiples of 4 must be greater than or equal to odd number (if there are odd words), at the same time, an even number must be at least 2, 1 3 5 4 4 4 2 2 2 2 2 2 2 2 2 * if(Four >= Jishu) && (Oushu >= 2)) { $ return true;Panax Notoginseng } - the return false; + } A the Public Static voidMain (string[] args) { +Scanner in =NewScanner (system.in); - intnum =in.nextint (); $ intN; $ int[] A; - for(inti = 0; i < num; i++) { -n =in.nextint (); theA =New int[n]; - for(intj = 0; J < N; J + +) {WuyiA[J] =in.nextint (); the } - Booleanb =isrequired (n, a); Wu if(b) { -System.out.println ("Yes"); About}Else { $System.out.println ("No"); - } - } - } A}
NetEase 2018 School Recruit Pen Test-array can not meet the reordering of any adjacent element product is a multiple of 4