Blue Bridge cup Java basic Practice Turtle Rabbit Race Forecast

Source: Internet
Author: User

The problem is that there are all kinds of rabbits and turtles in the world, but the study found that all rabbits and turtles share a common trait-like running. So in all corners of the world, the tortoise and the Hare were constantly playing, and Xiao Hua was very interested in it, so he decided to study the race of different rabbits and turtles. He found that although rabbits run faster than turtles, they have a well-known problem-pride and laziness, so in the game with the tortoise, once any second end of the rabbit found themselves ahead of T-meter or more, they will stop to rest s seconds. For different rabbits, the values of t,s are different, but all the turtles are the same-they never stop until they reach the end.
However, some games are very long, the whole view will take a lot of time, and Xiao Hua found that as long as each game began to record the rabbit and turtle data-Rabbit speed V1 (indicating the rabbit can run V1 meters per second), the Turtle's Speed v2, and the rabbit corresponding t,s value, as well as the length of the track l-- You can predict the outcome of the game. But Xiao Hua is very lazy, do not want to calculate the result by hand calculation, so he found you--Tsinghua University computer department brilliant student-ask for help, please write a program, for the input of a game data v1,v2,t,s,l, predict the results of the game. Input format input has only one row, containing five positive integer v1,v2,t,s,l separated by spaces, where (v1,v2<=100;t<=300;s<=10;l<=10000 and v1,v2 common multiple) output format output contains two lines, The first line outputs the result of the match-a capital letter "T" or "R" or "D", respectively, that the turtle wins, the Hare wins, or both reach the end point.
The second line outputs a positive integer that represents the amount of time (in seconds) that the winner (or both sides) has to reach the end point. Example input 10 5 5 2 20 sample Output D
4 Example Input 10 5 5 1 20 sample output R
3 Example Input 10 5 5 3 20 sample output T
4
1 ImportJava.util.Scanner; 2   3  Public classMain {4      Public Static voidMain (string[] args) {5Scanner sc =NewScanner (system.in); 6   7          while(Sc.hasnext ()) {8             intV1 =Sc.nextint (); 9             intV2 =Sc.nextint (); Ten             intt =Sc.nextint ();  One             ints =Sc.nextint ();  A             intL =Sc.nextint ();  -    -             intS1 = 0;  the             intS2 = 0;  -             intTime = 0;  -              while(S1 < l && S2 <l) { -                 if(S1-s2 >= T) {//Rabbit Stop +                     if((L-S2)/V2 < s) {//The turtle reaches the finish line first -Time + = (L-S2)/v2;  +S2 =l;  A}Else{//The turtle can't reach the end atTime + =s;  -S2 + = v2 *s;  -                     }   -    -}Else{//Rabbits Keep -time++;  inS1 + = V1 * 1;  -S2 + = v2 * 1;  to                 }   +             }   -             if(S1 >S2) {   theSystem.out.println ("R");  * System.out.println (time);  $}Else if(S1 <S2) {  Panax NotoginsengSystem.out.println ("T");  - System.out.println (time);  the}Else {   +System.out.println ("D");  A System.out.println (time);  the             }   +    -         }   $    $     }   -    -}

Blue Bridge cup Java basic Practice Turtle Rabbit Race Forecast

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.