zoukankan      html  css  js  c++  java
  • 【LightOJ】[1198]Karate Competition

    1198 – Karate Competition

    Time Limit: 2 second(s)

    Memory Limit: 32 MB

    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 2 points, 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

    Output for Sample Input

    Case 1: 4

    Case 2: 2

    Case 3: 4

    Case 4: 5


    与田忌赛马的贪心策略类似

    不过因为输了不扣分平局加一分

    所以对平局的优先级需要提升一些

    【杭电】[1052]Tian Ji — The Horse Racing

    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    int a[55],b[55];
    int main() {
        int T,kase=0;
        scanf("%d",&T);
        while(T--) {
            int n;
            scanf("%d",&n);
            for(int i=0; i<n; i++)
                scanf("%d",&a[i]);
            for(int i=0; i<n; i++)
                scanf("%d",&b[i]);
            sort(a,a+n);
            sort(b,b+n);
            int cnt=0;
            int al=0,ar=n-1,bl=0,br=n-1;
            for(int i=0; i<n; i++) {
                if(a[ar]>b[br]) {
                    ar--,br--;
                    cnt+=2;
                } else if(a[ar]<b[br]) {
                    al++,br--;
                } else if(a[al]>b[bl]) {
                    al++,bl++;
                    cnt+=2;
                } else {
                    if(a[al]==b[br])
                        cnt++;
                    al++,br--;
                }
            }
            printf("Case %d: %d
    ",++kase,cnt);
        }
        return 0;
    }

    题目地址:【LightOJ】[1198]Karate Competition

  • 相关阅读:
    《数据结构第一章复习》
    《图的基本操作》
    《矩阵的一些基本操作》
    <矩阵的基本操作:矩阵相加,矩阵相乘,矩阵转置>
    《两个二维数组(矩阵)相乘》
    C#隐藏与显示系统任务栏和开始菜单栏按钮
    C#通过窗体属性缩小一定尺寸时,无法再缩小窗体尺寸问题
    C#一个窗体调用另一个窗体的方法
    C#异步线程
    C#中MessageBox.Show问题(让提示窗口不显示在任务栏中)
  • 原文地址:https://www.cnblogs.com/BoilTask/p/12569442.html
Copyright © 2011-2022 走看看