Tian Bogey horse racing

Source: Internet
Author: User
Tags integer numbers

Title Description

Horse racing is an ancient game, as early as Fourth century BC in China, in the state of the vassal, historically known as the "Warring States period." In the sun bin of the Wei officials, because of the persecution of his colleague Pangjuan, was rescued by the national envoy, reached the state of Qi.
Horse racing was the most popular pastime of the noble Qi. Up to the king, down to the minister, often to the horse's amusement, and to gamble and win. Tian bogey many times with the king and other ministers bet winning and losing, repeatedly bet lose. One day he lost his horse and went home unhappy. Sun Bin comforted him, said: "Next time you have the opportunity to take me to the racecourse to see, maybe I can help you." ”
After careful observation, Sun bin found that the horse and other horses and other people's horse is not far away, but the use of inappropriate strategies, resulting in failure.
Before the game Tian bogey in accordance with the idea of Sun bin, with the first-class saddle to decorate the inferior horse, posing as a good horse, and the King horse race. The second game, or in accordance with the arrangement of Sun Bin, Tian bogey with their best horse and the king of the medium horse race, in a cheer, saw the horse unexpectedly rushed to the king of the horse in front, won the second game. The key third field, Tian bogey medium horse and King of the inferior horse race, Tian bogey horse again rushed to the King's horse in front, results 2:1, Tian Bogey won the king.
It is so simple, now the Yuan son also to race a horse race. Suppose each horse has a constant speed, so the speed of the horse must be smaller than the speed of the horse first to the end (no accident!!) )。 No draw is allowed. In the end who wins more than half (excluding half), who is the winner (probably no winner). There are N (1≤n≤1000) horses in the race. The number of horses in the opponent is the same as the number of horses, and the speed of all horses is known. Smart you can predict the outcome of this century war and see if the yuan can win the game.

Input

Input has multiple sets of test data.
Each set of test data consists of 3 rows:
The first line is input N (1≤n≤1000). Indicates the number of horses.
The second line has n integer numbers, that is, the velocity of the N horses.
The third line has n integer numbers, that is, the speed of the opponent's n horses.
When n is 0 o'clock exits.

Output

If you carefully arrange through the wise, if the yuan can win the game, then output "YES".
Otherwise output "NO".

Sample input
52 3 3 4 51 2 3 4 542 2 1 22 2 3 10
Sample output
YESNO
Idea: After sorting, with the yuan of the horse began to compare, starting from the first, if small, with the yuan's second horse than the other side of the first, greater than the words, repeat the above method, compared to do not compare.

Import java.util.*;

public class Main { public static void main (string[] args) {      scanner sc = new Scanner (S ystem.in);         while (true) {     int num = Sc.nextint ();      int []a = new Int[1000];     int []b = new int[ 1000];     int Count =0;     int temp=0,res=0;      if (num = 0) break;     for (int i=0;i<num;i++) {       int a1 = Sc.nextint ();       a[i] = a1;      }     for (int i=0;i<num;i++) {      int B1 = Sc.nextint ();       b[i] = b1;     }           for (int i =0;i<num-1;i++) {      for (int j=i;j<num;j++) {       if (a[i]>a[j]) {         temp = A[i];        a[i] = a[j];    &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;A[J] = temp;       }       }     }          for ( int i =0;i<num-1;i++) {      for (int j=i;j<num;j++) {        if (B[i]>b[j]) {        temp = b[i];         b[i] = b[j];        b[j] = temp;        }      }     }           for (int j = 0;j<num;j++) {        if (A[j]>b[count])        count++;     }      if (COUNT&GT;NUM/2) {      system.out.println ("YES");      }else{      system.out.println ("NO");      }    } } }

Tian Bogey horse racing

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.