2016 Blue Bridge Cup quiz (Java)

Source: Internet
Author: User
Tags int size sca

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 class A{public static int F (String s) {return s.split ("________________"). Length; public static void Main (string[] args) {System.out.println (f ("12+35*5-2*18/9-3"));//7system.out.println (f ("354*12+ 3-14/7*6 ")); 6}}

public class A{public static int F (String s) {return s.split ("\\p{punct}"). Length; public static void Main (string[] args) {System.out.println (f ("12+35*5-2*18/9-3"));//7system.out.println (f ("354*12+ 3-14/7*6 ")); 6}}


Second,

1/1 + 1/2 + 1/3 + 1/4 + ... Is mathematically called the harmonic progression.

It is divergent, that is, if you add enough items, you can get arbitrarily large numbers.

However, it radiates slowly:

Top 1 Items and reach 1.0
Top 4 items and only over 2.0
The first 83 items and only more than 5.0

So, would you please calculate how many items you want to add to make and reach or exceed 15.0?

Please fill in this integer.

Note: Just fill in an integer and don't fill in any extra content. such as explanatory text.

1835421

public class Main {public    static void Main (string[] args) {    Double sum = 0.0;    Boolean flag = true;    for (int i = 1;; ++i) {    sum + = 1.0/i;    if (sum >= 15.0) {    System.out.println (i);    Break;}}}}    

Three


Can you calculate the approximate value of x if the x power of X is 10 (see Figure 1.png)?

Obviously, this value is a number between 2 and 3.

Please calculate the value of X to 6 decimal places (rounded) and fill in this decimal value.

Note: Only fill in a decimal, do not write any extra symbols or instructions.


2.506184

public class Main {static double EPS = 1e-7;    public static void Main (string[] args) {    double L = 2,r = 3,mid;    while (L+eps < R) {    mid = (l+r)/2;    if (Math.pow (Mid,mid) <)    L = mid;    else    r = Mid;    }    System.out.printf ("%.6f\n", L);    }}

Four,

Today there are 7 pairs of numbers: Two 1, two 2, two 3, ... Two of 7, line them up.
requirements, two 1 have 1 other figures, two 2 have 2 other figures, and so on, two 7 have 7 other figures. Here is an arrangement that meets the requirements:

17126425374635

Of course, if you turn it upside down, it also meets the requirements.

Please find another arrangement that fits the requirements, and this arrangement is preceded by 74.

Note: Only fill in this 14-bit integer, can not fill in any unnecessary content, such as explanatory notes.

74151643752


Five

 
  The hypotenuse of the known right triangle is an integer and requires that the other two edges must also be integers.

  To find the number of different right triangle that satisfy this condition.

Data Format
Enter an integer n (0<n<10000000) to represent the length of the right triangle hypotenuse. The
requires the output of an integer that represents the number of right triangle that satisfy the condition.

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

Again for example, enter:
+
Program should output:
2

Again for example, enter:
3
Program should output:
0

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

Please output strictly as required, do not print like this: "Please enter ..." Redundant content.

All the code is placed in the same source file, and after debugging passes, 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 handled by 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 (), cnt = 0;int t = (int) math.sqrt (n*n/2.0), for (int i = 1; I <= t; ++i) {int j = (int) math.sqrt (n*n*1 .0-i*i); if (i*i+j*j = = N*n) ++cnt;} SYSTEM.OUT.PRINTLN (CNT);}}


Six,

You must have heard of the Sudoku game.
For example, the player needs to infer the number of all remaining spaces according to the known numbers on the 9x9 disk, and the numbers in each row, column, and color nine are 1-9 and do not repeat.

The answer to Sudoku is unique, so multiple solutions are also known as non-solutions.

The figures in this figure are said to be the more difficult topic that Finnish mathematicians have spent 3 months designing. But I'm afraid it's a breeze for you to use computer programming.

The requirement of the topic is to enter Sudoku, the only solution of the program output Sudoku. We guarantee that all known data formats are legal and that the title has a unique solution.

Format requirements, enter 9 lines, 9 characters per line, 0 for unknown, and other numbers to be known.
Output 9 lines, 9 numbers per line represents the solution of Sudoku.

For example:
Input (that is, the title in the picture):
005300000
800000020
070010500
400005300
010070006
003200080
060500009
004000030
000009700

The program should output:
145327698
839654127
672918543
496185372
218473956
753296481
367542819
984761235
521839764

Again, for example, enter:
800000000
003600000
070090200
050007000
000045700
000100030
001000068
008500010
090000400

The program should output:
812753649
943682175
675491283
154237896
369845721
287169534
521974368
438526917
796318452

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

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.ArrayList;  Import java.util.List; Import Java.util.scanner;public class Main {public static void Main (string[] args) {list<int[][]> solutions; Scanner SCA = new Scanner (system.in); int data[][] = new INT[9][9]; String str = new string (), for (int i = 0, i < 9; i++) {str = Sca.nextline (); for (int j = 0; J < 9; J + +) {Data[i][j] = St R.charat (j)-' 0 ';}} int n = 9;DLX DLX = new DLX (n*n*n+1,4*n*n);d lx.setnum (5);d lx.solve (data); solutions = Dlx.getsolutions (); int solution[][] = Solutions.get (0); for (int i = 0, i < 9; i++) {for (int j = 0; J < 9; J + +) {System.out.print (integer.tostring (Solution[i][j]));} System.out.println ();}}}      Class dlx{private static final int ROW = 4096 + 50;      private static final int COL = 1024 + 50;      private static final int N = 4 * 9 * 9;        private static final int m = 3;      Dlxnode row[] = new Dlxnode[row];      Dlxnode col[] = new Dlxnode[col];        Dlxnode Head;      private int n;      private int num = 2; private int size[] = new Int[col];      int data[][] = new INT[9][9];        List<int[][]> Solutions;          Public DLX (int r, int c) {n = m * m;          Head = new Dlxnode (r, c); Head. U = head. D = head. L = head.          R = head;              for (int i = 0; i < C; ++i) {Col[i] = new Dlxnode (r, I); Col[i].              L = head; Col[i]. R = head.              R Col[i]. L.R = Col[i].              R.L = Col[i]; Col[i]. U = Col[i].              D = Col[i];          Size[i] = 0;              } for (int i = r-1; i >-1; i--) {Row[i] = new Dlxnode (i, c); Row[i].              U = head; Row[i]. D = head.              D Row[i]. U.D = Row[i].              D.U = Row[i]; Row[i]. L = Row[i].          R = Row[i];          }} public void AddNode (int r, int c) {Dlxnode p = new Dlxnode (r, c);          P.R = Row[r]; P.L = Row[r].          L          P.L.R = P.R.L = P;          P.U = Col[c]; P.D = Col[c].          D     P.U.D = P.D.U = P;     ++SIZE[C];          } public void AddNode (int i, int j, int k) {int r = (I * n + j) * n + k;          AddNode (R, I * n + k-1);          AddNode (r, N * n + J * n + k-1);          AddNode (r, 2 * N * n + block (i, j) * n + k-1);      AddNode (r, 3 * n * n + i * n + j);      } int block (int x, int y) {return x/m * m + y/m;            } public void cover (int c) {if (c = = N) return;          Col[c].dellr ();          Dlxnode R, C; for (C = Col[c]. D C! = Col[c];              C = c.d) {if (c.c = = N) continue; for (R = C.L; R! = C;                  R = R.L) {if (r.c = = N) continue;                  --SIZE[R.C];              R.delud ();          } C.DELLR ();            }} public void resume (int c) {if (c = = N) return;          Dlxnode R, C; for (C = Col[c]. U C! = Col[c]; C = c.u) {if (c.c = = N)                  Continue              C.RESUMELR (); for (R = C.R; R! = C;                  R = R.R) {if (r.c = = N) continue;                  ++SIZE[R.C];              R.resumeud ();      }} COL[C].RESUMELR (); } public boolean solve (int depth) {if (head.              L = = head) {int solution[][] = new Int[n][n]; for (int i = 0, i < n; ++i) for (int j = 0; J < N; ++j) solution[i][j] = data[              I][J];                Solutions.add (solution);              if (solutions.size () = = num) return true;          return false;          } int minSize = 1 << 30;          int c =-1;          Dlxnode p; for (P = head. L P! = Head;                  p = p.l) {if (Size[p.c] < minSize) {minSize = size[p.c];              c = p.c;            }} cover (c); for (P = col[c]. D P! = CoL[C];              p = p.d) {Dlxnode cell;              P.R.L = p; for (cell = P.L; cell! = p; cell = cell.              L) {cover (CELL.C);              } P.R.L = P.L;              int rr = p.r-1;              DATA[RR/(n * N)][rr/n% n] = RR% n + 1;                if (Solve (depth + 1)) return true;              P.L.R = p; for (cell = P.R; cell! = p; cell = cell.              R) resume (CELL.C);          P.L.R = P.R;          } resume (c);      return false;          } public boolean solve (int data[][]) {init (data);      return solve (0);          } public void init (int data[][]) {solutions = new arraylist<int[][]> ();          int I, j, K;                    for (i = 0, i < n; i++) {for (j = 0; J < N; j + +) {if (Data[i][j] > 0) {                  AddNode (i, J, Data[i][j]);   }else{for (k = 1; k <= N; ++k)                       AddNode (I, J, K); }}}} public int getnum () {return num;} public void setnum (int num) {this.num = num;}      Public list<int[][]> getsolutions () {return solutions;      }} class dlxnode{int r,c;            Dlxnode U,d,l,r;      Dlxnode () {r = c = 0;          } dlxnode (int r, int c) {THIS.R = R;      THIS.C = C;          } dlxnode (int r, int c, Dlxnode U, Dlxnode D, Dlxnode L, Dlxnode r) {THIS.R = R;          THIS.C = C; This.          u = u; This.          D = D; This.          L = l; This.      R = r;          } public void Dellr () {L.R = R;      R.L = L;          } public void Delud () {u.d = D;      d.u = U;      } public void Resumelr () {L.R = R.L = this;      } public void Resumeud () {u.d = d.u = this;   }  }


Seven,

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.
The next number of n-1, respectively, is numbered 2, 3, ..., the direct superior number of the soldiers of N, number I of the soldier's direct superior number is less than I.
Output format
Outputs an integer that represents the number of scenarios for sending out the Expendables. Because the number can be large, you only need to output the remainder of this number except 10007.
Sample Input 1
3
1 1
Sample Output 1
4
Sample Description
These four ways are:
1. Select 1;
2. Select 2;
3. Select 3;
4. Select 2, 3.
Sample Input 2
7
1 1 2 2 3 3
Sample Output 2
40

Data size and conventions
For 20% of data, n≤20;
For 40% of data, n≤100;
For 100% of data, 1≤n≤100000.

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

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 quiz (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.