Directory
1 Topic one
2 Topic two
3 Topic three
Foreword: The following code is for reference only, if has the mistake welcome to correct OH ~
1 topic one
support for regular expressions is provided in Java. Sometimes, the proper use of the regular, can make our work more than a multiplier! The following code is used to verify the number of data items in a arithmetic type, please fill in the missing code in the underlined section. Note: Fill in the missing code only, and do not write any superfluous content, for example, existing double quotes. Public classa{ Public Static intF (String s) {returnS.split ("________________"). length; } Public Static voidMain (string[] args) {System.out.println (f ("12+35*5-2*18/9-3"));//7System.out.println (f ("354*12+3-14/7*6"));//6}} Answer: [ ^0-9]
2 topic two
1/1 + 1/3+ 1.02.05.015.0? Please fill in this integer. Note: Just fill in an integer and don't fill in any extra content. such as explanatory text. Answer: 1835421
1 Public classMain {2 3 Public Static voidMain (string[] args) {4 Doubleresult = 0;5 for(inti = 1;i < 10000000;i++) {6Result = result + 1.0/i;7 if(Result >= 15.0) {8 System.out.println (i);9SYSTEM.OUT.PRINTLN ("result =" +result);Ten Break; One } A } - } - the}
3 topic three
General G has a well-trained army, the Army, except General G, each soldier has a direct superior (perhaps other soldiers, may be general G). General G will now receive a special mission to send some of the soldiers (at least one) to form a Suicide squad, in order to increase the independence of the Expendables, to ask if a soldier in the death squads, his direct superiors can not be in the death squad. Excuse me, General G has how many ways to send the Expendables. Note that General G can also enter the Expendables as a soldier. Input format the first line of input contains an integer n, representing the number of troops including General G. Army soldiers numbered from 1 to N and general G numbered 1. Next n-1 numbers, denoted by 2, 3, respectively, ..., the direct superior number of the Soldier of N, number I of the soldier's direct ancestor's number is less than I. Output format output An integer that indicates the number of scenarios that sent out the Expendables. Because the number can be large, you only need to output the remainder of this number except 10007. Sample Input 131 1Sample Output 14Examples of these four methods are:1. Option 1;2. Option 2;3. option 3;4. Select 2, 3. Sample Input 271 1 2 2 3 3Sample Output 240data size and engagement% of data, n≤20; for% of data, n≤100; for the% of data, 1≤n≤100000. Resource contract: Peak memory consumption (with virtual machines)<256MCPU Consumption<2000ms 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.
references: Blue Bridge Cup-G general (tree)
1 Importjava.util.ArrayList;2 ImportJava.util.Scanner;3 4 Public classMain {5 Public Static intN;6 Public Static intMOD = 10007;7 Public StaticArraylist<integer>[] list;8 Public Static Long[] DP;9 Ten Public voidDfsintroot) { OneDp[root][0] = 1; ADP[ROOT][1] = 1; - for(inti = 0;i < List[root].size (); i++) { - intChild =List[root].get (i); the DFS (child); -Dp[root][0] = dp[root][0] * (dp[child][0] + dp[child][1])%MOD; -DP[ROOT][1] = dp[root][1] * Dp[child][0]%MOD; - } + } - +@SuppressWarnings ("Unchecked") A Public Static voidMain (string[] args) { atMain test =NewMain (); -Scanner in =NewScanner (system.in); -n =in.nextint (); -List =NewArraylist[n + 1]; - for(inti = 1;i <= n;i++) -List[i] =NewArraylist<integer>(); in for(inti = 2;i <= n;i++) { - intFather =in.nextint (); to List[father].add (i); + } -DP =New Long[n + 1] [2]; theTest.dfs (1); * Longresult = (Dp[1][0] + dp[1][1]-1)%MOD; $ System.out.println (result);Panax Notoginseng } -}
Algorithm Note _215: Sixth session Blue Bridge Cup software class part of the real problem (Java language Group B)