lightoj1198 - Karate Competition
来源:互联网 发布:犀牛软件安装包 编辑:程序博客网 时间:2024/05/19 18:48
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
#include<stdio.h>#include<algorithm>using namespace std;int main(){int t,n,an,bn;int a[55],b[55];int i,j,sum;int l=1;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)scanf("%d",&b[i]);sort(a,a+n);sort(b,b+n);sum=0;i=0,j=0;an=bn=n-1;while(n--){if(a[i]>b[j]){sum+=2;i++;j++;}else if(a[an]>b[bn]){sum+=2;an--;bn--; } else if(a[i]<b[bn]) { bn--; i++;}else {sum++;i++;j++;}}printf("Case %d: %d\n",l++,sum);}return 0;}
- lightoj1198 - Karate Competition
- lightoj 1198Karate Competition
- lightoj 1198 - Karate Competition
- Karate Competition(贪心)
- LOJ 1198 Karate Competition
- 【LightOJ 1198】- Karate Competition
- 【LightOJ】[1198]Karate Competition
- lightoj 1198 - Karate Competition 贪心
- lightoj 1198 - Karate Competition 【贪心】
- LightOJ - 1198 Karate Competition 【贪心】
- lightoj-1198 - Karate Competition【贪心】
- LightOJ - 1198 Karate Competition (贪心)
- Light oj 1198 Karate Competition 【贪心】
- LightOJ - 1198 Karate Competition(带权二分图)
- 【Light-oj】-1198 - Karate Competition(贪心+双端队列)
- lightoj 1198Karate Competition(田忌赛马变形)
- LightOJ 1198Karate Competition(动态规划+dp)
- 【LightOJ】1198 - Karate Competition(贪心 & 双端队列)
- 我的第一篇博客
- 《算法导论》第四章_读书笔记
- hdu 2717 Catch That Cow (BFS)
- 数据结构之单链表的几个简单算法题
- 冒泡排序最好的情况下复杂度O(N)的原因
- lightoj1198 - Karate Competition
- Linux -- 压缩
- LearnOpenGL学习笔记2:绘制基础图形
- 仿微信 滑动页面 Fragment ViewPager
- swift-运算符
- 203_自定义Dialog
- Reactjs 入门实例教程
- Android_浅谈mvp开发模式
- 排序算法小结