Gizmo - Yuanzi Horse Racing

1 Problem description

Horse racing is an ancient game. As early as the fourth century BC, China was in a state of separatist feudal lords, known in history as the "Warring States Period". Sun Bin, who was an official in the state of Wei, was persecuted by his colleague Pang Juan, and after being rescued by the envoys of the state of Qi, he arrived at the capital of the state of Qi. Horse racing was the most popular entertainment among the nobles of Qi State at that time. Up to the king, down to the ministers, they often take pleasure in horse racing and gamble with huge sums of money to win or lose. Tian Ji won and lost many bets with the king and other ministers, and repeatedly lost. One day he lost the horse race again and came home gloomy. Sun Bin comforted him and said, "Next time you have the opportunity to take me to the racecourse, maybe I can help you." After careful observation, Sun Bin found that Tian Ji's horse was not far from other people's horses, but it was just an improper use of strategies that led to failure. . Before the competition, according to Sun Bin's idea, Tian Ji decorated the inferior horse with a superior saddle, pretended to be a superior horse, and competed with the superior horse of the King of Qi. In the second match, according to Sun Bin's arrangement, Tian Ji used his top horse to compete with the king's middle horse. Amid the cheers, Tian Ji's horse rushed in front of King Qi's horse and won the second match. In the crucial third game, Tian Ji's middle horse competed with the king's inferior horse. Tian Ji's horse once again rushed in front of the king's horse. The result was two to one, and Tian Ji won the king. It's that simple, now Yuanzi is also coming to race a horse. Assume that each horse has a constant speed, so the faster horse must reach the finish line before the slower horse (no surprise!!). A tie is not allowed. Whoever wins more than half of the games at the end (excluding half) is the winner (maybe there is no winner). Yuanzi has  N(1\leq N\leq 1000)N ( 1 N 1 0 0 0 )  horses compete. The opponent has the same number of horses as Yuanzi and knows the speed of all the horses. Be smart to predict the outcome of this battle of the century and see if Yuanko can win the game.

input format

Enter multiple sets of test data. Each set of test data includes  33 lines: the first line input N(1\leq N\leq 1000)N ( 1 N 1 0 0 0 ) . Indicates the number of horses. The second row has NN integer numbers, that is, N of Yuanzi The speed of N  horses. The third row has NN  integer numbers, the opponent's NThe speed of N  horses. when NN  is 0 Exit at 0 .

input format

If it is carefully arranged by you cleverly, if Yuko can win the game, then output YES. Otherwise output NO.

sample input

Sample output



2 Reference code (C++)

#include<bits/stdc++.h>
using namespace std;
int n;
int a[1010],b[1010];
intmain()
{
    int i,j,win=0;
    while(cin>>n&&n!=0)
    {
        for(i=0;i<n;i++)
            cin>>a[i];
        for(i=0;i<n;i++)
            cin>>b[i];
        sort(a,a+n);
        sort(b,b+n);
        for(i=0,j=0,win=0;i<n;i++)
        {
            if(a[i]>b[j])
            {
                win++;
                j++;
            }
        }
        if(win>n/2)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324852357&siteId=291194637