Seventh session (16) Blue Bridge Cup Java Group B final real title

Source: Internet
Author: User

1. Angry Birds (fill in the blanks)
Planet X Angry Birds like to hit the train!

A straight track, 1000 meters between the two trains.
The two trains (which may be called A and b) travel at 10 m/s per hour.

Angry Birds from a car, speed 50 m/s, crashed into B car,
Then go back to hit a car, and then back to hit B car, so reciprocating ....
The two trains are parked 1 metres apart.

Q: How many times has the angry bird hit the B car?

Note: You need to submit an integer (indicating the number of times you crashed the B car), do not fill in any other content.

1   Public classOne {2     //A, B's position A, B's size relative to A's starting point, the bird's speed is 50,a, B's speed all is ten3      Public Static Doublesum=0;//sum used for the number of collisions between birds and b during the specified period4      Public Static voidFunb (DoubleADoubleb) {//in the distance A, b birds hit B by a5         if(b-a<=1){6 System.out.println (sum);7             return;8         }9         DoubleTime= (b-a)/(50+10);//the time when the bird and B collided during the distance of A and BTenA=a+10*time;//the position of a after hitting OneB=b-10*time;//the position of B after the crash Asum++; -Funa (A, b);//The bird turns to a when the bird and B collide. -         return; the     } -      -      Public Static voidFuna (DoubleADoubleb) {//birds Fly by B to a -         if(b-a<1) {//if the distance between the bird and the B is less than 1 after the collision, then sum-- +sum--; - System.out.println (sum); +         } A         DoubleTime= (b-a)/(50+10); atA=a+10*time;//the position of a after hitting -B=b-10*time;//the position of B after the crash - Funb (A, b); -         return; -     } -      Public Static voidMain (String args[]) { in         Doublea=0,b=1000; - Funb (A, b); to     } +}
Angry Birds (two recursive functions)

The answer is: 9

2. Anti-Magic side (fill in the blanks)
The ancient books of our country record very early

2 9 4
7 5 3
6 1 8
This is a third-order magic side. Each row and the number on the diagonal are added equally.

Consider the opposite problem below.
It is not possible to fill nine Gongge with 1~9 numbers.
So that the numbers on each diagonal of each row are not equal to each other?

This should be able to do.
Like what:
9 1 2
8 4 3
7 5 6

Your task is to search all third-order anti-magic squares. and count the total number of species.
Rotate or mirror the same type.


Like what:
9 1 2
8 4 3
7 5 6

7 8 9
5 4 1
6 3 2

2 1 9
3 4 8
6 5 7
are counted as the same situation.

Please submit the number of third-order anti-magic side altogether. This is an integer, do not fill in any superfluous content.

1  Public classMain {2      Public Static intsum = 0;//counter3 4      Public Static voidFunintA[],intN) {5         if(n = = 9) {6 text (a);7             return;8}Else {9              for(inti = n; I < 9; i++) {//N Behind theTen                 inttemp =A[i]; OneA[i] =A[n]; AA[n] =temp; -Fun (A, n + 1); -                 intTamp =A[i]; theA[i] =A[n]; -A[n] =tamp; -             } -         } +     } -  +      Public Static voidTextinta[]) { A         intL1 = a[0] + a[1] + a[2]; at         intL2 = A[3] + a[4] + a[5]; -         intL3 = A[6] + a[7] + a[8]; -         intS1 = a[0] + a[3] + a[6]; -         intS2 = a[1] + a[4] + a[7]; -         intS3 = A[2] + a[5] + a[8]; -         intX1 = a[0] + a[4] + a[8]; in         intx2 = a[2] + a[4] + a[6]; -         if(L1! = L2 && L1! = L3 && L1! = S1 && L1! = S2 && L1! = S3 && L1! = x1 && L 1! =x2) to             if(L2! = L3 && L2! = S1 && L2! = S2 && L2! = S3 && L2! = x1 && L2! =x2) +                 if(L3! = S1 && L3! = S2 && L3! = S3 && L3! = x1 && L3! =x2) -                     if(S1! = S2 && S1! = S3 && S1! = x1 && S1! =x2) the                         if(S2! = S3 && s2! = x1 && S2! =x2) *                             if(S3! = x1 && S3! =x2) $                                 if(X1! =x2)Panax Notoginsengsum++; -     } the      Public Static voidMain (string[] args) { +         inta[]={1,2,3,4,5,6,7,8,9};  AFun (a,0);  theSystem.out.print (SUM/8);  +     } -}
third-order anti-magic Square (Recursive)

The answer is: 3120



Seventh session (16) Blue Bridge Cup Java Group B final real title

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.