Light OJ 1198
来源:互联网 发布:牛津大学古典学数据库 编辑:程序博客网 时间:2024/06/04 19:23
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
代码:#include<stdio.h>#include<algorithm>using namespace std;int a[55],b[55];int main(){int t,n,k=1,la,lb,ra,rb;scanf("%d",&t);while(t--){int A=1,B=1;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}for(int i=1;i<=n;i++){scanf("%d",&b[i]);}sort(a+1,a+n+1);sort(b+1,b+n+1);int ans=0;la=lb=1;ra=rb=n;for(int i=1;i<=n;i++){if(a[ra]>b[rb]){ra--;rb--;ans+=2;}else if(a[ra]<b[rb]){rb--;la++;}else{if(a[la]>b[lb]){la++;lb++;ans+=2; }else{if(a[la]==b[rb]) ans++;la++;rb--;}}}printf("Case %d: %d\n",k++,ans);}return 0; }
- Light OJ 1198
- light oj
- light oj
- Light OJ
- Light OJ
- Light oj 1198 Karate Competition 【贪心】
- Light OJ 1000
- Light OJ 1001
- Light OJ 1008
- Light OJ 1022
- Light OJ 1015
- Light OJ 1042
- light oj 1128
- Light OJ 1055 BFS
- Light OJ Beginners Problems
- Light OJ Basic Geometry
- Light OJ Basic Math
- light oj 1124
- 树形结构的数据库表设计
- JavaScript的字符串去空格
- Gesture Recognizers与触摸事件分发
- java对象、静态、继承及super
- FreeBSD学习总结
- Light OJ 1198
- 【Ceph】centos7搭建Ceph集群(jewel)
- C语言学习2
- unity 语音识别
- golang获取当天零点时间
- go web服务(2)
- 机器学习面试问题9
- Sublime Text 3 配置 PHP IDE环境 并使用Xdebug进行调试
- 【poj 3067 cdoj 383】Japan 树状数组