" OJ" "Algorithm Total chapter" "OJ" "038-INOC product Division-Yang Hui Triangle deformation" "Project download" topic description
1 1 1 1 1 2 3 2 1 1 3 6 7 6 3 11 4 10 16 19 16 10 4
Enter a description
输入一个int整数
Output description
输出返回的int值
Input example
4
Output example
3
Algorithm implementation
ImportJava.util.Arrays;ImportJava.util.Scanner;/** * Author: Wang Junshu * date:2015-12-24 16:41 * All rights Reserved!!! */ Public class Main { Public Static void Main(string[] args) {Scanner Scanner =NewScanner (system.in);//Scanner Scanner = new Scanner (Main.class.getClassLoader (). getResourceAsStream ("Data.txt")); while(Scanner.hasnext ()) {intinput = Scanner.nextint (); SYSTEM.OUT.PRINTLN (FindIndex (input)); } scanner.close (); }Private Static int FindIndex(intN) {if(N <=2) {return-1; }int[] arr = {New int[2N1],New int[2N1],New int[2N1]}; arr[0][0] =1; arr[1][0] =1; arr[1][1] =1; arr[1][2] =1; for(inti =2; I < n; i++) {intCurr = i%3;intPrev = (I-1) %3;intLast =2I//Last subscriptarr[curr][0] =1;//Set first valuearr[curr][1] = i;//Set a second valueArr[curr][last] =1;//Set the countdown to the first valueArr[curr][last-1] = i;//Set the second value to the bottom for(intj =2; J <= Last-2; J + +) {Arr[curr][j] = arr[prev][j-2] + arr[prev][j-1] + arr[prev][j]; } }intCurr = (N-1) %3; for(inti =0; i < arr[curr].length; i++) {if(Arr[curr][i]%2==0) {returni +1; } }return-1; }}
" OJ" "038-INOC product Division-Yang Hui Triangle deformation"