lightoj-1198 - Karate Competition【贪心】
来源:互联网 发布:linux 更改时区 编辑:程序博客网 时间:2024/05/19 17:52
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<cstdio>#include<algorithm>using namespace std;int a[100],b[100];bool cmp(int a,int b){return a>b;}int main(){int t,test=0;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&a[i]);for(int i=0;i<n;i++)scanf("%d",&b[i]);sort(a,a+n,cmp);sort(b,b+n,cmp);int amax=0,amin=n-1;int bmax=0,bmin=n-1;int win=0,cnt=0;for(int i=0;i<n;i++){if(a[amax]>b[bmax]){win++;amax++;bmax++;}else if(a[amax]<b[bmax]){amin--;bmax++;}else{if(a[amin]>b[bmin]){win++;amin--;bmin--;}else if(a[amin]<b[bmin]){amin--;bmax++;}else if(a[amin]<b[bmax]){amin--;bmax++;}else if(a[amin]==b[bmin]){cnt++;amin--;bmin--;}}}printf("Case %d: %d\n",++test,win*2+cnt);}return 0;}
- lightoj 1198 - Karate Competition 贪心
- lightoj 1198 - Karate Competition 【贪心】
- LightOJ - 1198 Karate Competition 【贪心】
- lightoj-1198 - Karate Competition【贪心】
- LightOJ - 1198 Karate Competition (贪心)
- lightoj 1198Karate Competition
- lightoj 1198 - Karate Competition
- 【LightOJ 1198】- Karate Competition
- 【LightOJ】[1198]Karate Competition
- 【LightOJ】1198 - Karate Competition(贪心 & 双端队列)
- Light oj 1198 Karate Competition 【贪心】
- Karate Competition(贪心)
- LightOJ - 1198 Karate Competition(带权二分图)
- lightoj 1198Karate Competition(田忌赛马变形)
- LightOJ 1198Karate Competition(动态规划+dp)
- LOJ 1198 Karate Competition
- 【Light-oj】-1198 - Karate Competition(贪心+双端队列)
- lightoj1198 - Karate Competition
- HDU 1847 Good Luck in CET-4 Everybody! (巴什博弈)
- 深入讨论 java类加载器
- HDU-5777 domino
- 前台和后台的数据交互
- Android 基本UI控件
- lightoj-1198 - Karate Competition【贪心】
- Visual Studio的相关插件安装:UE4.natvis和UnrealVS Extension
- C#控制台 类的实例化变量.tostring()什么作用
- Gym 100971F Two Points
- Python and or
- 南阳理工学院ACM语言入门题目1的思考
- 策略模式
- 死锁详解
- 部署tomcat方案时,出现红色叹号,并且显示file lock