首页 技术 正文
技术 2022年11月15日
0 收藏 975 点赞 3,136 浏览 2605 个字

1198 – Karate Competition

   PDF (English) Statistics Forum
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


PROBLEM SETTER: JANE ALAM JAN思路:贪心;本来用贪心去做,想了半天不知道咋贪心,然后这个有点像二分匹配,想要用最大流来做,发现建图不对,后来网上搜了题解,虽然AC了,但是还是有点模糊。方法是这样的,先将两个数组升序排序,然后贪心的选取,比当前数小的加入优先队列,然后选取小于这个数的最大值,(这是为了让小的尽量适配前面那些不能找到比自己小的数)。也就是先把大于的找出,最后扫一边等于的。

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<stdlib.h>
6 #include<queue>
7 #include<set>
8 using namespace std;
9 int ans1[200];
10 int ans2[200];
11 bool flag[200];
12 bool flag1[200];
13 typedef struct pp
14 {
15 int x;
16 int id;
17 bool operator<(const pp &cx)const
18 {
19 return cx.x>x;
20 }
21 } ss;
22 int er(int n,int m,int ak,int ac[]);
23 int main(void)
24 {
25 int i,j,k;
26 scanf("%d",&k);
27 int s;
28 int n,m;
29 for(s=1; s<=k; s++)
30 {
31 scanf("%d",&n);
32 priority_queue<ss>que;
33 memset(flag,0,sizeof(flag));
34 memset(flag1,0,sizeof(flag1));
35 for(i=0; i<n; i++)
36 {
37 scanf("%d",&ans1[i]);
38 }
39 for(i=0; i<n; i++)
40 {
41 scanf("%d",&ans2[i]);
42 }
43 sort(ans1,ans1+n);
44 sort(ans2,ans2+n);
45 int sum=0;
46 int uu=0;
47 for(i=0;i<n;i++)
48 {
49 while(ans2[uu]<ans1[i]&&uu<n)
50 {
51 ss cc;
52 cc.id=uu;
53 cc.x=ans2[uu];
54 que.push(cc);
55 uu++;
56 }
57 if(!que.empty())
58 {
59 sum+=2;
60 ss ak=que.top();
61 que.pop();
62 flag[i]=true;
63 flag1[ak.id]=true;
64 }
65 } int ac[200];int vv=0;
66 for(i=0;i<n;i++)
67 {
68 if(!flag[i])
69 {
70 for(j=0;j<n;j++)
71 {
72 if(!flag1[j]&&ans1[i]==ans2[j])
73 {
74 sum+=1;
75 flag1[j]=true;
76 break;
77 }
78 }
79 }
80 }
81 printf("Case %d: %d\n",s,sum);
82 }
83 return 0;
84 }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901