zoukankan      html  css  js  c++  java
  • csuoj-1722-Race

    题目:

    Description

    Johnson and Bob are crazy motorcycle collecting enthusiasts. In order to prove their own motorcycles is the best, they issued a challenge to each other. Johnson wants to win the challenge.As a good friend of Johnson’s, you need to give advice to Johnson. Johnson and Bob each can select their best n motorcycles. And each motorcycle has a value v. There are n matches in total. Any motorcycle can be chosen optionally to participate in the match(but each motorcycle can only participate once). Each time the motorcycle with high value will win. Johnson gets the order of Bob’s motorcycles in advance. Can you help Johnson arrange the competition order of motorcycles in order to win the most of the matches?

     

    Input

    First line input an integer T(mean there are T cases)
    In each case , first line input an integer n (mean there are n motorcycles) (0<n<=10000)
    Next line input n integers (mean the value of Johnson’s n motorcycles)
    Next line n integers (mean the value of Bob’s n motorcycles )

    Output

    Every case output an integer mean the most match can win.

    Sample Input

    1
    5
    6 4 5 1 3
    8 9 3 4 7

    Sample Output

    2
    分析:
    设Johnson的数组为a,Bob的数组为b。为了尽可能赢得更多的比赛,从a数组中最大的开始匹配b数组中最大的并且小于该值的值,直至b数组中没有元素可以匹配。
    代码:
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int a[10000];
    int b[10000];
    int main(){
        int t;
        cin >> t;
        while(t--){
            int n;
            cin >> n;
            for(int i = 0;i < n;i++) cin >> a[i];
            for(int i = 0;i < n;i++) cin >> b[i];
            sort(a,a + n);
            sort(b,b + n);
            int ans = 0;
            int indexa,indexb;
            indexa = indexb = n - 1;
            while(indexb != -1){
                if(a[indexa] > b[indexb]){
                    indexa--;
                    indexb--;
                    ans++;
                }
                else indexb--;
            }
            cout << ans << endl;
        }
        return 0;
    }

  • 相关阅读:
    动态规划-神奇的口袋V1
    独立项目-建立Web服务器-00
    连接数据库时出现:SQL Server 建立连接时出现与网络相关的或特定于实例的错误
    独立项目-MemoryStream-内存数据读写-01
    独立项目-场景刷怪、小怪AI、主角战斗、小怪死亡-01
    独立项目-角色控制器FSM-FSM有限状态机-03
    独立项目-角色控制器FSM-AnimatorController学习-02
    独立项目-角色控制器FSM-学习内容-01
    Unity中的UGUI之Rect Transform__02
    矩阵的平移、旋转与缩放
  • 原文地址:https://www.cnblogs.com/tracy520/p/6702135.html
Copyright © 2011-2022 走看看