zoukankan      html  css  js  c++  java
  • Bravebeart

    E - Bravebeart
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    standard input/output
    Statements

    Would you want to fight against bears riding horses? Me neither.

    Limak is a grizzly bear. He is a general of the dreadful army of Bearland. The most important part of an army is the cavalry of course.

    The cavalry of Bearland consists of n warriors and n horses, both numbered 1 through n. Limak knows the strength of each warriorw1, w2, ..., wn and of each horse h1, h2, ..., hn.

    A warrior together with his horse is called a unit. The strength of a unit is equal to the multiplied strengths of a warrior and a horse.

    General Limak must assign all horses to warriors, one horse per warrior. The cavalry will consist of n units then.

    The first warrior (the one with the strength w1) is called Bravebeart. He is always the first to charge the enemy. Limak decided that Bravebeart deserves some respect and his unit must be the strongest one, with no ties allowed. But is it possible?

    Help Limak and check whether there is an assignment of horses to warriors for which the Bravebeart's unit is strictly stronger than any other unit. Print "YES" or "NO" (without the quotes).

    Input

    You are given multiple test cases.

    The first line of the input contains one integer T (1 ≤ T ≤ 50), denoting the number of test cases.

    For each test case the first line contains one integer n (2 ≤ n ≤ 42).

    The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 1000), denoting strengths of warriors. The first number is the strength of Bravebeart.

    The third line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 1000), denoting strengths of horses.

    Output

    For each test case find the answer and print it in a separate line.

    Print "YES" (without the quotes) if there is an assignment where the strength of the Bravebeart's unit is strictly greater than strength of any other unit. Otherwise print "NO" (without the quotes).

    Sample Input

    Input
    2
    6
    12 9 7 1 20 10
    3 6 4 7 5 5
    4
    5 17 10 1
    200 400 800 600
    Output
    YES
    NO

    Hint

    In the first test case Bravebeart can take a horse of strength 6 to get the unit strength 12·6 = 72.

    In one way of assigning other horses to warriors the pairs (strength of warrior, strength of horse) are: (9, 7), (7, 5), (1, 5), (20, 3),(10, 4). Units strengths would be 63, 35, 5, 60 and 40, respectively. Indeed, the Bravebeart's unit is stronger than any other unit then.

    In the second test case it's impossible to assign horses to warriors so that Bravebeart's unit is stronger than any other one.

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 
     7 int cmp(int a,int b){
     8     return a>b;
     9 }
    10 
    11 int main()
    12 {
    13     int t;
    14     int n;
    15     int w[50];
    16     int h[50];
    17     scanf("%d",&t);
    18     for(int j=0;j<t;j++){
    19         int bb=0;
    20         scanf("%d",&n);
    21         for(int i=0;i<n;i++){
    22             scanf("%d",&w[i]);
    23         }
    24         for(int i=0;i<n;i++){
    25             scanf("%d",&h[i]);
    26         }
    27         sort(w+1,w+n,cmp);
    28         sort(h,h+n);
    29         int braveheart=w[0]*h[n-1];
    30         for(int i=1;i<n;i++){
    31             if(w[i]*h[i-1]>=braveheart){
    32                 printf("NO
    ");
    33                 bb=1;
    34                 break;
    35             }
    36         }
    37         if(bb==1){
    38             continue;
    39         }
    40         printf("YES
    ");
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    mui 点击输入框软键盘弹起解决
    Vue中form表单常用rules校验规则
    ios new Date('yyyy-MM-dd HH-mm-ss').getTime() 方法获取不到时间戳
    uni-app运行到手机报错 Component constructors should be called while initialization. A constructor call has been ignored.
    vue-element-admin后台 点击侧边栏 刷新当前路由
    vue 防抖和节流
    vue data数据变化 页面数据不更新问题
    uni-app中页面部分内容使用索引列表(uni-indexed-list),动态数据
    css 文本单行显示溢出时出现省略号 多行显示溢出时出现省略号 首行缩进
    css实现两个div并排等高(一个div高度随另一个高度变化而变化)
  • 原文地址:https://www.cnblogs.com/TWS-YIFEI/p/6005939.html
Copyright © 2011-2022 走看看