Tian Bogey horse racing Java solution

Source: Internet
Author: User


You must have heard the story of Tian-ji horse racing, right?
If 3 horses become 1000, King still let his horse in the order of favorably to inferior, Tian bogey can choose his horse racing in any order. Win a game, Tian Bogey can get 2002 silver, lose a game, Tian Bogey will lose 2002 silver, draw words do not lose not win. How much can Tian bogey win?

About input:
The input contains multiple sets of test data, and the first line of each set of test data is an integer n (1<=n<=1000), which means that both Tian bogey and King have n horses. The next line is n integers, which indicates the speed of the horse, and the next line is also n integers, indicating the speed of the King's Horse. The last entry ends with a 0 representation.

About output:

For each group of data, the output of an integer, that is, Tian bogey can win more than the amount of silver, if the field bogey win, on the output a negative number, that is the minimum amount of tin bogey to lose.

Example input:

3
the
about
2
the
the
2
about
the
0

Example output:
$
0
0

Package Tianjisaima;import Java.util.scanner;import Java.util.list;import java.util.arraylist;import Java.util.Collections;          public class main{public static void Main (String args[]) {int n, m;        List<integer> list1=new arraylist<integer> ();        List<integer> list2=new arraylist<integer> ();              Scanner in=new Scanner (system.in);          while (true) {n=in.nextint ();            if (n==0) break;              input data for (int i = 0; i < n; ++i) {List1.add (In.nextint ());              } for (int i = 0; i < n; ++i) {List2.add (In.nextint ());              }//Processing data collections.sort (LIST1);                    Collections.sort (LIST2);              int i=0, j=0, x=n-1, y=n-1,count=0;                    Boolean blast=true;    while (bLast) {//is the last horse if (x==i)                  Blast=false;                      if (List1.get (x) > List2.get (y)) {//If Tian bogey the best horse can win King the best horse, then a x--;                      y--;                  count+=200;                      } else if (List1.get (i) > List2.get (j)) {//If Tian Bogey's worst horse can win King's worst horse, then a                      i++;                      j + +;                  Count + = 200;                          } else {///Otherwise, the worst horse and king of the field is the best one if (List1.get (i) < List2.get (y))                      Count-= 200;                      i++;                  y--;           }} System.out.println (count); List1.clear ();
List2.clear (); } } }

Tian Bogey horse racing Java solution

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.