河南多校大一训练赛 (类似田忌赛马)

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 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

Sample Output

Case 1: 4

Case 2: 2

Case 3: 4

Case 4: 5

  用最快的马与对方最快的马比,如果比对方的马快,先赢一场,否则比较最慢的马和对方最慢的马,若比对方的马快,再赢一场,否则如果比较最慢的马和对方最快的马,如果比对方最快的马快,赢一场。

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<string.h>
 4 using namespace std;
 5 int main()
 6 {
 7     int t,n,sum,a[1010],b[1010],key[1010],k,j,i,s,num;
 8     scanf("%d",&t);
 9     num=0;
10     while(t--)
11     {
12         scanf("%d",&n);
13         for(i = 0 ;i<n;i++)
14         {
15             scanf("%d",&a[i]);
16         }
17         for(i=0;i<n;i++)
18         {
19             scanf("%d",&b[i]);
20         }
21         sum=0;
22         sort(a,a+n);
23         sort(b,b+n);
24         k=n-1;
25         s=0;
26         j=0;
27         for(i=n-1;i>=j;i--)
28         {
29             if(a[i] > b[k])
30             {
31                 sum+=2;
32                 k--;
33             }
34             else if(a[i] < b[k])
35             {
36                 k--;
37                 j++;
38                 i++;
39             }
40
41             else
42             {
43                 if(a[j] > b[s])
44                 {
45                     sum+=2;
46                     j++;
47                     s++;
48                     i++;
49                 }
50                 else
51                 {
52                     if(a[j] == b[k])
53                     {
54                         sum++;
55                         j++;
56                         k--;
57                         i++;
58                     }
59                     else
60                     {
61                         j++;
62                         k--;
63                         i++;
64                     }
65                 }
66
67
68             }
69         }
70         printf("Case %d: %d\n",++num,sum);
71     }
72 }
时间: 2024-07-30 09:02:52

河南多校大一训练赛 (类似田忌赛马)的相关文章

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分相同,第一部分与第二部分对称. 现在给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法,求出以第i个点为中心的回文串长度,记录到数组p中 要满足题目所要求的内容,需要使得两个相邻的回文串,共享中间的一部分,也就是说,左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也是一样. 因为我们已经记录下来以

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&amp;#39;s problem(manacher+二分/枚举)

pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法.求出以第i个点为中心的回文串长度.记录到数组p中 要满足题目所要求的内容.须要使得两个相邻的回文串,共享中间的一部分,也就是说.左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也

校队训练赛,同时也是HDU4497(数论:素数分解+组合数学)

一.题目 http://acm.hdu.edu.cn/showproblem.php?pid=4497 二.思路 将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y',x') = 1,同时lcm(x',y',x') = G/L.特判,当G%L != 0 时,无解.然后素数分解G/L,假设G/L = p1^t1 * p2^t2 *````* pn^tn.满足上面条件的x,y,z一定为这样的形式.x' = p1^i1 * p2^i2 *```* pn^in.y' =

hdu 5361 2015多校联合训练赛#6 最短路

In Touch Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 67    Accepted Submission(s): 11 Problem Description There are n soda living in a straight line. soda are numbered by  from left to ri

HDU 5358(2015多校联合训练赛1006) First One (区间合并+常数优化)

HDU 5358 题意: 求∑?i=1?n??∑?j=i?n??(?log?2??S(i,j)?+1)?(i+j). 思路: S(i,j) < 10^10 < 2^34,所以log2(S)+1的值只可能在1~35之间.由于log变化缓慢的函数特性,我们可以S(i,n)分作多个相同log值的区间来计算,用pos[i][j]预处理记录每个以i为起点,log(s)值为j的区间的右边界,即可优化至nlogn的复杂度. 主要是写起来比较难一些,一些细节比较纠结,一定思路理清后再写. ps.此题卡常数毫无

hdu 5358 First One 2015多校联合训练赛#6 枚举

First One Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 142    Accepted Submission(s): 37 Problem Description soda has an integer array a1,a2,-,an. Let S(i,j) be the sum of ai,ai+1,-,aj. No

hdu 5381 The sum of gcd 2015多校联合训练赛#8莫队算法

The sum of gcd Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 23    Accepted Submission(s): 4 Problem Description You have an array ,the length of  is Let Input There are multiple test cases.

河南多校联合训练 F 不是匹配

描述 有N个人,N个活动, 每个人只会对2个或者3个活动感兴趣, 每个活动也只有两个人或者两个活动对它兴趣,每个人参加一个 感兴趣的活动需要一天 ,且当天该活动被参加时,其他的人不能参加 如果每个人都参加完自己有兴趣的活动,应当怎样安排使得所用总天数时间最短 2<= N <=1000, 1<=m<=1000; 输入 一个数T 表示T 组数据每组一个N表示人数,编号1 -- N , 一个数 m ,接下来m 行每个两个数x,y, 表示第 x 个人对第y个活动感兴趣 输出 每组输出一个整

河南多校联合训练 南阳理工 1261 音痴又音痴的LT

描述 LT最近一直在无限循环薛之谦的歌,简直都中毒了!可是呢…他的歌LT还是不会唱(其实不止他的歌LT不会唱,所有人的歌LT都不会唱…因为LT是标准的音痴)可是LT又很喜欢唱歌(所以LT不仅是音痴还是音痴)…没错,这对于LT的室友来说简直是噩梦… 现在呢,LT有N次操作,每次操作只会有两种可能: I a: 表示着LT使用唱歌软件唱歌得到的分数. Q k: 表示着LT想知道自己得到的第k小的分数是多少.(如果没有第k小,输出-1) 输入 有多组输入(不超过20组),每组输入的第一行是一个N,表示有