2016 Blue Bridge Cup (Java)

Source: Internet
Author: User
Tags sca


Number of briquettes

There was a heap of briquettes, piled into triangular pyramid. Specific:
1 on the first floor,
The second Layer 3 (arranged into triangles),
The third layer of 6 (arranged into triangles),
Fourth layer 10 (arranged into triangles),
....
If there are 100 floors, how many briquettes are there?

Please fill in the total number of briquettes.
Note: You should submit an integer, do not fill in any superfluous content or descriptive text.

171700

public class Main {public static void main (string[] args) {int ans = 0;for (int i = 1; I <= ++i) ans + = (1+i) *I/2; System.out.println (ANS);}}



Birthday Candles

A gentleman has a birthday party every year starting from a certain year, and every time he blows out the candle with the same number of ages.

For now, he blew out 236 candles altogether.

Excuse me, how old did he start his birthday party?

Please fill in the age of his birthday party.
Note: You should submit an integer, do not fill in any superfluous content or descriptive text.

Algorithm idea:

At the beginning of the age of X, now the age of Y, then (x+y) (y-x+1)/2=236 violence.

26

public class Main {public static void main (string[] args) {for (int i = 1; I <=, ++i) {for (int j = i+1; J <= 100; ++J) {if ((i+j) * (j-i+1)/2 = 236) System.out.printf ("%d%d\n", i,j);}}}

Formula

B DEF
A +---+-------= 10
C GHI


In this equation A~i represents the number of 1~9, and the different letters represent different numbers. (the subject has changed during the game)

Like what:
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.


The



Sub-group

9 athletes participate in the competition and need to be divided into 3 groups for the preliminaries. What are the grouping scenarios for
?

We mark athletes as A,b,c,... I
The following program lists all the grouping methods.

The normal output of this program is:
ABC DEF GHI
ABC DEG FHI
ABC DEH FGI
ABC DEI FGH
ABC DFG EHI
ABC DFH EGI
ABC DFI EG H
ABC DGH EFI
ABC DGI EFH
ABC DHI EFG
ABC EFG DHI
ABC efh DGI
ABC EFI DGH
ABC Egh DFI
ABC EGI dfh< BR>ABC EHI DFG
ABC FGH DEI
ABC FGI DEH
ABC FHI DEG
ABC GHI DEF
Abd CEF GHI
Abd CEG FHI
Abd CEH fgi
abd CEI FGH
Abd CFG EHI
Abd CFH EGI
ABD CFI egh
ABD CGH EFI
Abd CGI efh
ABD CHI EFG
ABD EFG chi
. .... (omitted below, total 560 lines).

public class A{public static string remain (int[] A) {String s = ""; for (int i=0; i<a.length; i++) {if (a[i] = = 0) s + = (char) (i+ ' a ');} return s;} public static void F (String s, int[] a) {for (int i=0; i<a.length; i++) {if (a[i]==1) continue;a[i] = 1;for (int j=i+1; j< ; a.length; J + +) {if (a[j]==1) continue;a[j]=1;for (int k=j+1; k<a.length; k++) {if (a[k]==1) continue;a[k]=1; System.out.println (__________________________________);  Fill in the blanks a[k]=0;} a[j]=0;} A[i] = 0;}} public static void Main (string[] args) {int[] a = new int[9];a[0] = 1;for (int b=1; b<a.length; b++) {A[b] = 1;for (int c=b +1; c<a.length; C + +) {A[c] = 1; String s = "a" + (char) (b + ' a ') + (char) (c+ ' a '); F (s,a); a[c] = 0;} A[B] = 0;}}}



Read the code carefully and fill in the missing content from the underlined section.

Note: Do not fill in any existing content or descriptive text.

System.out.println (s+ "" + (char) (' a ' +i) + (char) (' a ' +j) + (char) (' a ' +k) + "" +remain (a));  Fill in the blanks

Draw

Planet X is sending a 5-man observer mission to the W-Star.
which
A country can send up to 4 people.
A maximum of 2 people can be dispatched in country B.
C countries can send up to 2 people.
....

So how many different combinations of the country will eventually be sent to the W-Star's Observer mission?

The following procedure resolves this problem.
Array a[] is the largest number of places each country can send.
The results of the program execution are:
Defff
Cefff
Cdfff
Cdeff
Ccfff
Cceff
Ccdff
Ccdef
Befff
Bdfff
Bdeff
Bcfff
Bceff
Bcdff
Bcdef
....
(omitted below, total 101 lines)

public class A
{
public static void F (int[] A, int k, int n, String s)
{
if (k==a.length) {
if (n==0) System.out.println (s);
Return
}

String s2 = s;
for (int i=0; i<=a[k]; i++) {
_____________________________; Fill in the blanks
S2 + = (char) (k + ' A ');
}
}

public static void Main (string[] args)
{
Int[] A = {4,2,2,1,1,3};

F (a,0,5, "");
}
}

Read the code carefully and fill in the missing content from the underlined section.

Note: Do not fill in any existing content or descriptive text.

f (a,k+1,n-i,s2);   Fill in the blanks



Number of squares to fill

The 10 squares below
+--+--+--+
|  |  | |
+--+--+--+--+
|  |  |  | |
+--+--+--+--+
|  |  | |
+--+--+--+

(See also if you have a problem with the display)

Fill in the number of 0~9. Requirement: Consecutive two digits cannot be contiguous.
(around, up and down, diagonal are counted adjacent)

How many kinds of possible filling schemes are there?

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.


Cut Stamps


As in "Figure 1", there are 12 stamps linked together in the 12 zodiac.
Now you have to cut 5 sheets from it, and the request must be attached.
(Connecting only one corner is not a link)
For example, "Figure 2", "Figure 3", the pink part is the qualified cut.


Please calculate, how many different ways to cut.

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.


Four Square and

Four squared sum theorem, also known as Lagrange's theorem:
Each positive integer can be represented as a sum of squares of up to 4 positive integers.
If 0 is included, it can be represented as a sum of 4 squares.

Like what:
5 = 0^2 + 0^2 + 1^2 + 2^2
7 = 1^2 + 1^2 + 1^2 + 2^2
(^ 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 press a,b,c,d for the combined primary key in ascending order, and finally output the first notation

Program input as a positive integer N (n<5000000)
Requires output of 4 non-negative integers, sorted from small to large, separated by spaces in the middle

For example, enter:
5
The program should output:
0 0 1 2

Again, for example, enter:
12
The program should output:
0 2 2 2

Again, for example, enter:
773535
The program should output:
1 1 267 838

Resource contract:
Peak memory consumption (with virtual machines) < 256M
CPU Consumption < 3000ms

Please strictly according to the requirements of the output, do not use the superfluous printing 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.

Import Java.util.scanner;public class Main {public static void main (String [] args) {Scanner SCA = new Scanner (system.in); I NT n = sca.nextint (), int maxn = (int) math.sqrt (n), Boolean flag = true;for (int a = 0; a <= maxn && flag; ++a) {f or (int b = A; b <= maxn && flag; ++b) {for (int c = b; c <= MAXN && flag; ++c) {int d = (int) math.sqrt (N-a*a-b*b-c*c), if (n = = a*a+b*b+c*c+d*d) {System.out.println (A + "" +b+ "" +c+ "" +d "; flag = FALSE;}}}}}


Game of taking the ball

Two players play the game of taking the ball.
A total of n balls, each of which takes the ball in turn, each of which is preferable to the set of {n1,n2,n3}.
If you cannot continue to take the ball, the game is over.
At this point, the party holding an odd number of balls wins.
If both are odd, it is a draw.

Assuming both sides are using the smartest methods,
Will the first person to take the ball win?
Try programming to solve this problem.

Input format:
The first line 3 positive integers n1 n2 N3, separated by a space, indicating the number of desirable each (0<n1,n2,n3<100)
The second row 5 positive integers x1 x2 ... x5, separated by spaces, indicating the number of initial balls of 5 innings (0<xi<1000)

Output format:
A line of 5 characters separated by a space. Whether the person who takes the ball first will win the game.
You can win the output +,
Second, if there is a way to flush opponents, output 0,
In any case will lose, then output-

For example, enter:
1 2 3
1 2 3) 4 5

The program should output:
+ 0 + 0-

Again, for example, enter:
1 4 5
10 11 12) 13 15

The program should output:
0-0 + +

Again, for example, enter:
2 3 5
7 8 9) 10 11

The program should output:
+ 0 0 0 0

Resource contract:
Peak memory consumption (with virtual machines) < 256M
CPU Consumption < 3000ms

Please strictly according to the requirements of the output, do not use the superfluous printing 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.

AC Code (Error):

Import Java.util.scanner;public class Main {public static int [] num = new INT[3];p ublic static int [] init = new Int[5];p ublic static int [] end = new int[1000];p ublic static char [] sign = {'-', ' 0 ', ' 0 ', ' + '};p ublic static void Main (String [] A RGS) {Scanner SCA = new Scanner (system.in); for (int i = 0; i < 3; i++) num[i] = Sca.nextint (); int minn = Math.min (Num[0], Math.min (Num[1], num[2])); for (int i = 0; i < 5; i++) Init[i] = Sca.nextint (); for (int i = 0; i < Minn; i++) end[i] = 2; for (int i = minn; i < end.length; i++) {int temp = 0;for (int j =0; J < 3; J + +) {if (I-num[j] < 0) Continue;else if ( END[I-NUM[J]] = = 3) {if (num[j]%2! = 0) temp = 1 > temp? 1:temp;} else if (end[i-num[j]] = = 0) {if (num[j]%2 = = 0) temp = 3;elsetemp = 2 > Temp? 2:temp;} else if (end[i-num[j]] = = 2) {if (num[j]%2==0) temp = 2 > temp? 2:temp;elsetemp = 3;} else if (end[i-num[j]] = = 1) {if (num[j]%2==0) temp = 1 > temp? 1:temp;}} End[i] = temp;} for (int i = 0; i < 5; i++) {System.out.print (sign[end[init[i]]]+ "");}}} 

Compression transformations


Xiao Ming is studying the compression algorithm recently.
He knows that if the compression is able to make the numerical value is very small, it can be obtained by entropy coding to obtain a higher compression ratio.
However, it is a challenge to make a small number.


More recently, Xiaoming needs to compress the sequence of positive integers, which are characterized by the large number of digits that appear later in the future. For this particular sequence, xiaoming prepares to make a transformation of the sequence to reduce the value of the number.


The process of transformation is as follows:
Enumeration sequence from left to right, each enumeration to a number, if this number does not appear, just convert the number to its opposite number, if the number appears, then it appears in the original sequence after the last occurrence (and before the current number) there are several numbers, the number of this type to replace the original number.


For example, sequences (A1, A2, A3, A4, A5) = (1, 2, 2, 1, 2) in the transformation process are:
A1:1 has not appeared, so A1 becomes-1;
A2:2 has not appeared, so A2 becomes-2;
A3:2 appeared, the last time for the original sequence of A2, after A2, A3 before there are 0 kinds of numbers, so A3 into 0;
A4:1 appeared, the last time for the original sequence of A1, after A1, A4 before there are 1 kinds of numbers, so A4 into 1;
A5:2 appeared, the last time for the original sequence of A3, after A3, A5 before there are 1 kinds of numbers, so A5 into 1.
Now, given the original sequence, what is the sequence transformed by this transformation rule?


Input format:
Enter the first line containing an integer n, representing the length of the sequence.
The second line contains n positive integers representing the input sequence.


Output format:
The output line, containing the number of N, represents the transformed sequence.


For example, enter:
5
1 2 2) 1 2


The program should output:
-1-2 0 1 1


Again, for example, enter:
12
1 1 2 3 2 3 1 2 2 2 3 1


The program should output:
-1 0-2-3 1 1 2 2 0 0 2 2


Data size and conventions
For 30% of data,n<=1000;
For 50% of data,n<=30000;
For 100% of data, 1 <=n<=100000,1<=ai<=10^9




Resource contract:
Peak memory consumption (with virtual machines) < 256M
CPU Consumption < 3000ms




Please strictly according to the requirements of the output, do not use the superfluous printing 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.


2016 Blue Bridge Cup (Java)

Related Article

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.