zoukankan      html  css  js  c++  java
  • Light oj 1198 Karate Competition 【贪心】

    Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu

    Submit Status uDebug

    Description

    Your karate club challenged another karate club in your town. Each club enters N players into the match, and each player plays one game against a player from the other team. Each game that is won is worth 2points, and each game that is drawn is worth 1 point. Your goal is to score as many points as possible.

    Your secret agents have determined the skill of every member of the opposing team, and of course you know the skill of every member of your own team. You can use this information to decide which opposing player will play against each of your players in order to maximize your score. Assume that the player with the higher skill in a game will always win, and if the players have the same skill then they will draw.

    You will be given the skills of your players and of the opposing players, you have to find the maximum number of points that your team can score.

    Input

    Input starts with an integer T (≤ 70), denoting the number of test cases.

    Each case starts with a line containing an integer N (1 ≤ N ≤ 50). The next line contains N space separated integers denoting the skills of the players of your team. The next line also contains N space separated integers denoting the skills of the players of the opposite team. Each of the skills lies in the range [1, 1000].

    Output

    For each case, print the case number and the maximum number of points your team can score.

    Sample Input

    4

    2

    4 7

    6 2

    2

    6 2

    4 7

    3

    5 10 1

    5 10 1

    4

    10 7 1 4

    15 3 8 7

    Sample Output

    Case 1: 4

    Case 2: 2

    Case 3: 4

    Case 4: 5

    Source

    Problem Setter: Jane Alam Jan

    这道题与田忌赛的题一样。
     
     
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <stack>
    #include <iostream>
    using namespace std;
    
    int main() {
        int t, n, mine[100], army[100];
        scanf("%d", &t);
        int cnt = 0;
        while (t--) {
            scanf("%d", &n);
            int ans = 0;
            for (int i = 0; i < n; i++)
                scanf("%d", &mine[i]);
            for (int j = 0; j < n; j++)
                scanf("%d", &army[j]);
            sort(mine, mine + n);
            sort(army, army + n);
            int bm = n-1, lm = 0, ba = n-1, la = 0;
            while (bm >= lm) {
                if (mine[lm] > army[la]) {
                    ans += 2;
                    lm++; la++;
                }
                else if (mine[lm] < army[la]) {
                    lm++; ba--;
                }
                else {
                    if (mine[bm] > army[ba]) {
                        ans += 2;
                        bm--; ba--;
                    }
                    else if (mine[bm] < army[ba]) {
                        lm++; ba--;
                    }
                    else {
                        if (mine[lm] < army[ba]) {
                            lm++; ba--;
                        }
                        else {
                            ans += bm - lm + 1;
                            break;
                        }
                    }
                }
            }
            printf("Case %d: %d
    ", ++cnt, ans);
        }
        return 0;
    }


  • 相关阅读:
    jQuery 插件为什么要return this.each()
    Android中TextView setText int 报错
    局部打印插件 jquery.PrintArea.js
    Jdbc Url 设置allowMultiQueries为true和false时底层处理机制研究
    mysql-unsha1:在未知密码情况下,登录任意MYSQL数据库
    Wireshark实战之抓包MySQL Java客户端
    linux 文件句柄数查看命令
    Java1.8 JDK源码中,对两个类进行 按位与 操作是什么意思
    linux下面覆盖文件,如何实现直接覆盖,不提示
    比特币算法——SHA256算法介绍
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770884.html
Copyright © 2011-2022 走看看