[Software Engineering - Blue Bridge Blue Bridge Cup third cup] JAVA Nations Championship Group B problem solutions

Fill in the blank 1. [Results] (out of 9 points)

The driving force behind the complex phenomenon, can be extremely simple principle. One goal of science is to find simple rules complicated natural phenomena behind. Einstein's theory of relativity is a model example of this.

Very early time, biologists observed the number of insects in a certain area (called the number of insect population) variation year by year, it is very confusing: sometimes is gradually increased to reach an equilibrium value. Sometimes beating cycle between two numbers. Sometimes it enters chaos, as similar random number variation (a phenomenon known as chaos).

Slowly, people are more clearly observed from mathematics to this phenomenon, and therefore created: the field of study of symbolic dynamics, nonlinear dynamics.

A number of well-known insect population simplified model is as follows:

x' = x * (1 - x) * r

Here, xx 'r are floating.

Where, x represents the number of insect population that year, x 'indicates the number of insect population next year. Their value ranges between 0 and 1, in fact, is represented: the total number of accounts for the largest number of insect population ratio environment can support.

r is a constant (parameter setting), r in the range [0,4].

Surprisingly: This simple iterative formula has an unusual mysterious nature!

In general, after several iterations, the initial value of a stable pattern of insect population and the number of x is independent, but associated with r!

For example: the initial value of x regardless of how much, when r = 2.5, and x the number of iterations will tend to 0.6.

When r = 3.2 when the value of x will tend to periodically oscillate between 0.799 and 0.513.

Then, r = 3.62, you observed what cyclical phenomenon happen?

 

Not required to submit the source code, as long as you can write your conclusion!

Write your answer: "Answers .txt" Do not write here.

Analysis Q & A:
This question I started to think that it is difficult, in fact, simply looked better title, is the result came out very strange, the answer is x appear chaotic state, I think the third batch is not artificial, anyway, I this certainly can not write the answer.

Code:

public class Main03JB01 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        float x=(float) (Math.random()*1);
        float r=(float) (Math.random()*1+4);
        for(int i=0;i<100000;i++){
            x=(float) ((float)x*(float)(1-x)*(float)3.62);
            System.out.println(x);
        }        
    }
}

 

  

[2] Code fill in the blank (12 minutes out)

/ * String "abcba" symmetrical with the letter "c" is about center; string "abba" is another mode symmetrical. In both cases we call this string is mirrored string. In particular, it contains only a letter string, the string can be seen as a mirror image of the first pattern.

A string may contain a number of image sub-string. Our goal is to find a maximum string substring mirror (mirror longest substring), if there are a plurality of maximum image substring, left center of symmetry of selected priority. For example: "abcdeefghhgfeiieje444k444lmn" maximum image substring is: "efghhgfe"

The following static methods to achieve this function, please read and analyze the code, fill in the blank code carefully, so that the logic of due process, the result is correct.
* /
// find the maximum (the maximum length) mirror-symmetrical sub-string
public static getMaxMirrorString String (String S)
{
String max_s = ""; // ask maximum symmetry substring

for (int i = 0; i <s.length (); i ++) // traverse the entire string, the idea is to force it enumeration, each letter over again from the beginning so that
{
// a first symmetrical pattern here should be traversed even length substring
int = STEP. 1;
the try {
for (;;)
{
IF (! s.charAt (I-STEP) s.charAt = (I + STEP)) BREAK;
STEP ++;
}
} the catch ( E Exception) {}

String S1 = s.substring (_____________________________); // fill in the blank 1

// second symmetric mode
STEP = 0;
the try {
for (;;)
{
IF (_________________________________) BREAK; // fill in the blank 2
STEP ++;
}
} the catch (Exception E)} {

String S2 = s.substring (I-STEP. 1 +, I + STEP +. 1);


IF (s1.length ()> max_s.length ()) = S1 max_s;
IF (S2 .length ()> max_s.length ()) = S2 max_s;
}

max_s return;
}

[Note]
to fill only missing part, do not transcribe existing code.
The code does not fill more than one sentence (sentence does not contain semicolons)
filled code is no longer than 256 characters.
Write your answer "answer .txt" Do not write here!

Analysis and Solution:
(1)
there are test sites, I started to do a little Mongolian This question should be familiar with the test sites for the job, in fact, is to extract the string, not difficult
substring () method returns the string of sub-characters string.
beginIndex - start index (including), 0 indexed.
endIndex - End index (not included).
(2)
The second point is the same idea, the odd note on the line, vertically symmetric readily occur

参考答案:
i-step+1, i+step
s.charAt(i-step) != s.charAt(i+step+1)

 

3. Programming [Title] (out of 22 points)

HTML (ie HTML), it is a markup language used to describe web pages of the document.

HTML through a text to describe the document should have displayed a "look." It is mainly defined by the object label display properties or behavior.

If the java source files copied directly into HTML documents, open a browser directly, you will find the original source files orderly was turned into a group. This is because many carriage returns and spaces in the text are ignored. And some symbols have a special meaning in html, causing a more complicated situation.

In order to be able to properly display the source file, we must add the appropriate label for the text. Special symbols escaping.

Commonly used are:
the HTML entity needs to be escaped:
& ---> & amp;
space ---> & nbsp;
<---> & lt;
> ---> & gt;
"---> & quot;
Further, according to the source characteristics that can put TAB into four spaces to display.
TAB ---> & nbsp; & nbsp; & nbsp; & nbsp;

To wrap shown as required <br/> End of line labels.

In order to display beautiful, keywords appear in bold, i.e., applied around the keyword <b> tag. such as:

<b>public</b>

For single-line comment text displayed in green, may be used <font> tag, like this:

<Font color = green> // This is my single-line comment! </ Font>

Note: If the "//" appears in the string is a distinction, not make the mistake turns green.

Does not consider the issue of multi-line comments (/ * .... * / or / * .... * /)

Your task is: to write programs, given the source files into the corresponding html expression.

[Input] output format required

And under the same directory as your program, there source file a.txt, where there is a standard java source files. Requirements to program it into b.html.

For example: The current a.txt file b.html file is corresponding. You can view the contents of the conversion b.html use Notepad to open. Open b.html you can see the effect of the display of the browser.

Note: a.txt use the example of the actual evaluation time is different.

【note】

Please debugging carefully! When your program can run only the correct result of a chance to score!

Please write all classes in the same file, debugging good, credited with [the candidates] folder corresponding to question number under "Answers .txt" can be.

Do not copy into the relevant project files.

Do not use a package statement.

JDK1.5 allowed syntax or call source program can only appear. You can not use version 1.6 or higher.

Analysis and Solution : third question This question is converted into html except this time I never did, at least I have never seen such a back problem, I never learned this topic, there are big brothers can answer, then answer about it, but I think this topic is unlikely examination. We are interested in doing it, I stole a lazy here.

 

[4] the programming problem (out of 23 points)

As the saying goes: 10 bet nine lost. Because behind most gambling they are in possession of a conspiracy. But not always the case, some hidden behind some gambling: "blatant lies."

One gamble is this: put the box on the table six, numbered 1-6. Many participants (hereinafter referred to as a player) can put any amount of money bet on a numbered box. After all players have bet while the dealer throws three dice (the numbers on the dice are 1-6). Winning or losing rules are as follows:

1. If the number of players on a bet on a dice box number of the same, the players get back their bets, the dealer paid according to the number of his bet (ie the odds of 1 to 1).

2. If the same two numbers on the dice and players bet the box number, the players get back their bets, the dealer paid according to the number of 2 times his bet (ie the odds ratio of 12).

3. If the numbers on the three dice are the same box number players bet, the players get back their bets, the dealer paid according to the number of six times his bet (ie the odds ratio of 16).

4. If the magazine number and the player is shown a number of dice to bet additional product equal to the product of two numbers shown dice, the player bets his back, not making payment (stream Board).

5. If there are more than satisfied by the rules, players can choose their best interest rules. When the rule runs, the rest of the harvest is bet on the box all bookmakers.

At first glance, as if the rules advantageous for the player, the dealer lose. But after a lot of combat, you will find the situation hard to say whether the dealer was suspected tampered with, making it very readily said: dice may be provided by the player, and can even be used to roll the dice by the player.

Your task is to: programmatically simulate the process. Analog 500,000, assuming that only one player, he always bet is a dollar, its bet box number is random. Suppose further that the dealer has sufficient funds for payment. Finally, calculate the profit rate of the dealer (the dealer profit amount / total amount bet).

[Input] output format required

Program no input, the program making the running output of interference, be rounded to three decimal places.


【note】

Please debugging carefully! When your program can run only the correct result of a chance to score!

Please write all classes in the same file, debugging good, credited with [the candidates] folder corresponding to question number under "Answers .txt" can be.

Do not copy into the relevant project files.

Do not use a package statement.

JDK1.5 allowed syntax or call source program can only appear. You can not use version 1.6 or higher.

Analysis Q & A: I thought it was the subject of game theory, then look closely simulation title, it will be relatively simply, the idea of simulation questions I did not do too much to do now, of course, I would have been not a few brush question, because I have not participated in any other race, so they are not so count on ac, but at least deal with the blue bridge cup or can, the idea of simulation questions I have always followed it around with the idea, because the general idea simulation questions in topic in will tell you. But I do not know enough to question the relationship between teacher experience, the Blue Bridge Cup this term how old some topics not marked answer it.

Code:

public  class Main03JB04 {
 static  int SUM = 0 ;
 public  static  void main (String [] args) {
 // the TODO Auto-Generated Method Stub 
int A = 0; // dice an 
int B = 0; // dice two 
int C = 0; // dice three 
int I = 0; // bet 
for ( int n-= 0; n-<500000; n-++) { // throw count 
A = ( int ) (Math.random () * +. 1. 6 ); 
B = ( int ) (Math.random () * +. 1. 6 ); 
C = (int ) (Math.random () * +. 1. 6 ); 
I = ( int ) (Math.random () * +. 1. 6 ); 
function (A, B, C, I); 
} 
Double RES = ( Double ) SUM / 500000f; 
System.out.printf ( "% .3f" , RES); 
} 
Private  static  void function ( int A, int B, int C, int I) {
 // the TODO Auto-Generated Method Stub
 // here is pit, at the beginning I have come to the subject in accordance with the order, so the answer is how counted wrong, did not understand the last sentence, first from the most favorable began to count. 
IF (A == B I && && C == I == I) { 
SUM - =. 6  ;
}else if(a==i&&b==i||c==i&&b==i||a==i&&c==i){
sum-=2;
}else if(a==i||b==i|c==i){
sum-=1;
}else if(!(a*b==i*c||b*c==i*a||a*c==i*b)){
sum+=1;
}
}
}

 



[Title] 5. Programming (out of 34 points)

This is an aspect matchsticks game. FIG [1.jpg], in a 3x4 grid, the sides alternately disposed game match stick. Its rules are:

1. Can not be placed where already placed matchsticks (that can only be placed in the box).

2. matchstick direction can only be vertical or horizontal position.

3. matchstick not "communicate" with other grid matches. The so-called two matchstick communication means can be connected into a straight line, and with no other matches in different directions "block."

For example: the figure [1.jpg] situation, may be vertically placed (for convenience of description lattice position, FIG left, are added to the marker), but not horizontally, as will communicate with the A2 at the C2 position. Similarly, B2, B3, D2 can not be placed at this time both orientations. But if placed vertically C2, D2 can be placed horizontally, because no longer in communication with A2 (C2, has been blocked).

4. The two sides take turns placing game matches, you can not abstain, can not put too much root. Continue until the party can not be placed, the negative side (one of the input).

When the game starts may have placed more than a match.

Your task is to: Write a program that reads the initial state, to calculate their best interest placement method and output.

FIG [1.jpg] situation is expressed as:
00-1
-000
0100

I.e., "0" indicates an idle position, a "1" is placed upright with the "-" indicates horizontally.
1
[input] output format required

User to input an integer n (n <100), indicating that the following n types of the initial situation of input, each representing the situation (situation no blank lines between a plurality of) three lines.

Program output: optimal placement method (column number + row number placement +) calculations of the initial situation in each case.
----------------

For example: a user input:
2
0111
-000
-000
1111
- ~ -----
0010
(not the input processing, make do with it)
then the program can output:
pm- 6
211

Not difficult to guess the meaning of the output is:

For the first situation, placed in the first row 0 0 level

For the second situation, placed vertically in the first column, line 2

note:

Row number, column number is counted from zero.

A plurality of optimal placement method (solution is not unique), to output only one kind of situation may for each.

For example, for a first situation 001 is positive solution; most second situation 201 is positive solution.

【note】

Please debugging carefully! When your program can run only the correct result of a chance to score!

Please write all classes in the same file, debugging good, credited with [the candidates] folder corresponding to question number under "Answers .txt" can be.

Do not copy into the relevant project files.

Do not use a package statement.

JDK1.5 allowed syntax or call source program can only appear. You can not use version 1.6 or higher.

 

Analysis Q & A:
be perfect:
it is no effort to write, I probably looked at this question should be the Game Theory + Search bar, later to write it, paste Gangster code.
https://blog.csdn.net/wr132/article/details/44345983

Code:
To be added:

Guess you like

Origin www.cnblogs.com/yyyyfly1/p/11894926.html