poj-1198

来源:互联网 发布:如何删掉淘宝评价图片 编辑:程序博客网 时间:2024/05/17 02:15


1198 - Karate Competition
   PDF (English)StatisticsForum
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 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

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

 

解题的思路就是 先找2的最后找分数为1 
 题意就是2个队伍比赛A B 他们多有各自的技能值,当A队中一个人的技能值大于B队中的一个技能值
 就会得到2分,相同时得1分,问A队能得到的最多的分数  
 一看我就知道用贪心,就像小时候的田忌赛马 但是想了好长时间,又看网上的代码才会(真菜)下面正题
 我们可以 在B队中找到一个人,再A队中找到一个人这个人的技能值刚好大于B队中这个人
 别忘了标记,找完之后在找平局的,(当时自己也是这样想的,一直没有实现,既然有了思路大家就赶快
 自己实现吧@_@) 


#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[2000],b[2000];int main(){int t,test=1;scanf("%d",&t);while(t--){int n,i,j;scanf("%d",&n);for(i=0;i<n;++i)scanf("%d",&a[i]);for(j=0;j<n;++j)scanf("%d",&b[j]);sort(a,a+n);sort(b,b+n);int sum=0; for(i=0;i<n;++i){if(a[i]==-1)continue;for(j=n-1;j>=0;--j){if(b[j]==-1)continue;if(a[i]>b[j])//找到刚好小于A组的一个值 {sum+=2;a[i]=b[j]=-1;break;}}}for(i=0;i<n;++i){if(a[i]==-1)continue;for(j=0;j<n;++j){if(b[j]==-1)continue;if(a[i]==b[j]){++sum;a[i]=b[j]=-1;break;}}}printf("Case %d: %d\n",test++,sum);}} 



0 0
原创粉丝点击