【LightOJ 1198】- Karate Competition

  • Karate Competition
  • 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
Output for 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
Case 1: 4
Case 2: 2
Case 3: 4
Case 4: 5

学长说的不错,我们畏难情绪太重,畏难情绪作祟这道题做了好久,
下次一定不会这样 还有 i 题 j 迟早会做出你们

#include<cstdio> 
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,t,n,m,ans,x,y,sum;
    int a[1055];
    int b[1055];
    scanf("%d",&t);
    m=1;
    while(t--)
    {
        scanf("%d",&n); 
        for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        sort(a,a+n);
        for(i=0;i<n;i++)
        scanf("%d",&b[i]);
        sort(b,b+n);
        ans=0;sum=0;
        x=n-1;y=n-1;
        i=0;j=0;
        while(i<=x&&j<=y)
        {
            if(a[i]>b[j])
            {
                ans+=2;
                i++;
                j++;
            }
            else if(a[i]<b[j])
            {
                i++;
                y--;
            }
            else 
            {
                if(a[x]>b[y])
                {
                ans+=2;
                x--;
                y--;
                }
              else 
              {
                if(a[i]==b[y])
                ans++;
                i++;
                y--;
             }
            }   
        }
        printf("Case %d: %d\n",m++,ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值