Full analysis of the sixth blue bridge cup provincial competition JAVA-B, Blue Bridge java-B

Source: Internet
Author: User

Full analysis of the sixth blue bridge cup provincial competition JAVA-B, Blue Bridge java-B

Two wrong orders are submitted, and gg is estimated.

Question 1:


I thought of using Helen's formula, and I figured it out. Well, if I subtract a small one, it will be done '''''

Answer: 8x8-(8x4)/2-4x6/2-8x2/2 = 28

Question 2:

Change the cube itself


Observe the following phenomenon. The percentile of a number is still equal to itself.
1 ^ 3 = 1
8 ^ 3 = 512 5 + 1 + 2 = 8
17 ^ 3 = 4913 4 + 9 + 1 + 3 = 17
...


Please calculate the total number of positive integers that match this property, including and 17?

It should be a language entry question,

public class Main {public static void solve(){}static long N,M;static long [] num = null;public static void main(String[] args) {long ans = 0;for(long n = 1;n<10000;n++){long tot = n*n*n;long cmp = 0;long t = tot;while(t!=0){cmp +=t%10;t /=10;}if(cmp == n){ans++;System.out.println(n);}}System.out.println("answer:"+ans);}}//1//8//17//18//26//27//answer:6

Question 3:

Sanyang xiangrui


Observe the following addition formula:


Xiang Ruisheng Hui
+ San Yang xiangrui
-------------------
San Yang is lucky

The same Chinese Character represents the same number, and different Chinese characters represent different numbers.
Please fill in the four digits represented by "sanyang xiangrui" (the only answer)

This is a mess.

9 5 6 7
1 0 8 5
1 0 6 5 2


Question 4:

Import java. util. Vector; public class Main {// The length of the loop section //// two integers are used for Division, and sometimes the circular decimal points are generated. The cyclic part is called the loop section. // For example, 11/13 = 6 => 0. 846153846153 ...... its cycle is [846153], with 6 digits in total. // The following method can be used to find the length of the cyclic section. //// Read the code carefully and enter the code that is missing in the dashes. Public static int f (int n, int m) {n = n % m; Vector v = new Vector (); for (;) {v. add (n); n * = 10; n = n % m; if (n = 0) return 0; if (v. indexOf (n)> = 0) return v. size ()-v. indexOf (n); // fill in the blanks} // Note: You can only fill in the missing part. Do not duplicate the existing code. Do not enter any additional text. Public static void main (String [] args) {System. out. println (f (11,13); System. out. println (f (11,17 ));}}

Question 5:

//// Nine array scores //// 1/3, 3... 9 the nine numbers constitute a score, its value is exactly, how to group? //// The program below implements this function. Please fill in the missing code in the dash section. Public class Main {public static void test (int [] x) {int a = x [0] * 1000 + x [1] * 100 + x [2] * 10 + x [3]; int B = x [4] * 10000 + x [5] * 1000 + x [6] * 100 + x [7] * 10 + x [8]; if (a * 3 = B) System. out. println (a + "" + B);} public static void f (int [] x, int k) {if (k> = x. length) {test (x); return;} for (int I = k; I <x. length; I ++) {int t = x [k]; x [k] = x [I]; x [I] = t;} f (x, k + 1); {int t = x [k]; x [k] = x [I]; x [I] = t;} // fill in the blanks, this is the full arrangement.} public static void main (String [] args) {int [] x = {1, 2, 4, 5, 6, 7, 8, 9}; f (x, 0 );}}


Question 6:

This is the test. The answer is: 16.

// Addition and variable multiplication // we all know: 1 + 2 + 3 +... + 49 = 1225 // now you are required to convert two non-adjacent plus signs into a multiplication sign, so that the result is 2015 /// For example: // 1 + 2 + 3 +... + 10*11 + 12 +... + 27*28 + 29 +... + 49 = 2015 // The answer that meets the requirements. //// Please find another possible answer and submit the number on the left of the multiplication number at the top (for example, submit 10 ). //// Note: You must submit an integer and do not enter any additional content. Import java. util. arrays; import java. util. vector; public class Main {public static void solve () {} static long N, M; static long [] num = null; public static void main (String [] args) {int pre = 1225; for (int p = 1; p <47; p ++) {for (int pp = p + 2; pp <49; pp ++) {int now = pre; now-= p + 1; now-= pp + 1; now + = p * (p + 1 ); now + = pp * (pp + 1); if (now = 2015) System. out. println (p + "" + pp );}}}}

Question 7:

Directly solve the problem with dp, however, I found the wrong question during the examination ,................................ ...............

import java.util.Arrays;import java.util.Scanner;public class Main {static int []num = new int[170];static int ans = 0;public static void main(String[] args) {int [][]dp = new int[14][14];dp[0][0]=1;for(int i = 1;i<14;i++)for(int j = 0;j<14;j++)for(int k = 0;k<5;k++)if(j+k<=13)dp[i][j+k] +=dp[i-1][j];System.out.println(dp[13][13]);}}//3598180


Question 8:

Note that the bottle cap is obtained after each calculation.

//// Exchange of drinks //// the legoat beverage factory is holding a promotional activity. Legoat C-type drinks, with three bottle caps can be another C-type beverage, and can be continuously circulating, but credit is not allowed. //// Calculate the total number of drinks that James can get for the first n bottles he bought if he does not waste bottle caps and tries to participate in the activity. /// Input: an integer of n, indicating the number of drinks (0 <n <10000). // output: an integer, indicates the actual number of drinks //// For example: // user input: // 100 // The program should output: // 149 /// user input: // 101 // The program should output: // 151 // resource Conventions: // peak memory consumption (including virtual machines) <256 M // CPU consumption <1000 ms //// please output as required strictly. Do not print similar information: "Please input.... //// Put all the code in the same source file. After debugging is passed, copy and submit the source code. // Note: Do not use the package statement. Do not use the features of jdk1.7 or later. // Note: The Main class name must be "Main"; otherwise, it will be processed according to invalid code. Import java. util. arrays; import java. util. role; public class Main {public static void main (String [] args) {role in = new role (System. in); int n = in. nextInt (); int ans = 0; int mod = 0; while (n! = 0) {ans + = n; int t = n; if (t % 3 + mod> = 3) {n = t/3 + 1; mod = (t % 3 + mod)-3;} else {n = t/3; mod + = t % 3;} System. out. println (ans );}}

Question 9:

Recursive, we still need to use matrix acceleration. If JAVA is too uncomfortable to write, it will not be written. It will be bare.

import java.util.Arrays;import java.util.Scanner;public class Main {static int MOD = (int) (1e9+7);public static void main(String[] args) {int [][]ar = new int[40][40];int []mm = {0,4,5,6,1,2,3};long [][]dp = new long[2][7];Scanner in = new Scanner(System.in);int n = in.nextInt();int m = in.nextInt();for(int i = 0;i<m;i++){int u  = in.nextInt();int v  =in.nextInt();ar[u][v] = 1;ar[v][u] = 1;}int pre = 1;int now = 0;for (int i = 1; i < 7; i++)dp[0][i] = 4;for (int i = 2; i <= n; i++) {pre = (pre + 1) % 2;now = (now + 1) % 2;Arrays.fill(dp[now], 0);for (int j = 1; j < 7; j++)for(int k = 1;k<7;k++){dp[now][j] += (dp[pre][k] * 4) % MOD;}for (int j = 0; j < 7; j++) {for(int k = 0;k<=j;k++) if(ar[j][k]==1){dp[now][mm[j]] = (MOD + dp[now][mm[j]] - dp[pre][k] * 4) % MOD;dp[now][mm[k]] = (MOD + dp[now][mm[k]] - dp[pre][j] * 4) % MOD;}}}long ans = 0;for (int i = 1; i < 7; i++)ans = (ans + dp[now][i]) % MOD;System.out.println(ans);}}

Question 10:

The question mark (LCA) does not correspond to the sample. It is strange that the question mark () times out.

// Tree of Life /// in forest X, God creates the Tree of Life. //// Each node (a leaf is also called a node) of each tree is indicated by an integer representing the harmonious value of this vertex. // God wants to select a non-empty node set S in this tree, so that any two vertices a and B in S have a point column {a, v1, v2 ,..., vk, B} makes each vertex in this vertex column an element in S, and an edge is connected between two adjacent vertices in the sequence. //// On this premise, God wants to make the sum of the integers corresponding to the points in S as big as possible. // The greatest sum is God's score on the Tree of Life. //// Through the atm's efforts, he has known the integers God has given to each node on each tree. However, because atm is not good at computing, he does not know how to calculate the score effectively. He needs you to write a program for him to calculate the score of a tree. /// "Input format" // an integer n in the first line indicates that the tree has n nodes. // N integers in the second row, indicating the scores of each node in turn. // In the next n-1 row, there are two integers u and v in each row, indicating that there is an edge between u and v. Because this is a tree, there is no ring. //// "Output format" // output a number in a row, indicating the score given by God to this tree. /// "Sample input" // 5 // 1-2-3 4 5 // 4 2/3 1/1 2/2 5 /// /"sample output" // 8 /// "data range" // for 30% of data, n <= 10 // for 100% of data, 0 <n <= 10 ^ 5, the absolute value of each node's score cannot exceed 10 ^ 6. /// Resource Conventions: // peak memory consumption (including virtual machines) <256 M // CPU consumption <3000 msimport java. util. arrays; import java. util. optional; public class Main {static int [] head1 = new int [100010]; static int [] head2 = new int [100010]; static int [] node = new int [100010]; static Edge [] edge1 = new Edge [300010]; static Edge [] edge2 = new Edge [300010]; static int [] degree = new int [100010]; static int [] fa = new int [100010]; static int tot1 = 0, tot2 = 0; static int Node; static long [] max = new long [100010]; static long ans = Long. MIN_VALUE; static void add1 (int u, int v) {edge1 [tot1]. u = u; edge1 [tot1]. v = v; edge1 [tot1]. nxt = head1 [u]; head1 [u] = tot1 ++;} static void add2 (int u, int v) {edge2 [tot2]. u = u; edge2 [tot2]. v = v; edge2 [tot2]. nxt = head2 [u]; head2 [u] = tot2 ++;} static void dfs (int u, int par, long nn) {max [u] = nn; fa [u] = u; for (int I = head 1 [u]; I! =-1; I = edge1 [I]. nxt) {int v = edge1 [I]. v; if (v = par) continue; dfs (v, u, nn + node [v]); fa [v] = u ;} for (int I = head2 [u]; I! =-1; I = edge2 [I]. nxt) {int v = edge2 [I]. v; if (max [v]! = Long. MAX_VALUE) {ans = Math. max (ans, max [v] + max [u]-max [parent (v)]) ;}} static int parent (int x) {if (fa [x] =-1 | fa [x] = x) return x; return fa [x] = parent (fa [x]);} public static void main (String [] args) {region in = new region (System. in); Node = in. nextInt (); for (int I = 0; I <Node; I ++) node [I] = in. nextInt (); for (int I = 0; I <= Node + Node; I ++) edge1 [I] = new Edge (); for (int I = 0; I <= Node * 2; I ++) edge2 [I] = new Edge (); Arrays. fill (fa,-1); Arrays. fill (head1,-1); Arrays. fill (head2,-1); Arrays. fill (max, Long. MAX_VALUE); for (int I = 1; I <Node; I ++) {int u, v; u = in. nextInt ()-1; v = in. nextInt ()-1; degree [u] ++; degree [v] ++; add1 (u, v); add1 (v, u );} for (int I = 0; I <Node; I ++) for (int j = 0; j <Node; j ++) {add2 (I, j ); add2 (j, I);} if (Node = 2) {System. out. println (node [0] + node [1]); return;} dfs (0,-1, node [0]); System. out. println (ans) ;}} class Edge {int u, v, nxt; int par ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.