lightoj-1198 - Karate Competition【贪心】

来源:互联网 发布:linux 更改时区 编辑:程序博客网 时间:2024/05/19 17:52

1198 - Karate Competition
   PDF (English)StatisticsForum
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

 

其实就跟田忌赛马差不多


#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;}



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 母亲满足了我的要求 子与母床上大战小说 穷山村的娘和儿子全文阅读 乱辈真实故事福林 为什么我没有朋友 妈毛又多又黑 脱掉母亲的白衬衫 漫画 母亲臀部抬起配合我 跟儿子洗澡没忍住做了一次 偷摸熟睡的母H 母亲只好认命抬起右腿 晚上故意到儿子房间睡 小说母亲的短裤衩 抱着母亲的腰疯狂地耸小说 姑妈穿裙子坐在我的腿的故事上 儿子18妈 妈38片国中 顶开高贵母亲的两辨 第章母亲抬腰迎合 母亲开始抗拒慢慢变迎合我口诉 母亲开始抗拒慢慢迎合我 第章顶开高贵母亲两瓣 母亲从抗拒慢慢变的迎合我 母亲疯狂迎合我txt小说下载 来吧儿子妈要你 影视片 儿子进来今晚妈让你做个够电影 儿子今晚妈让你做人个够知音网 离婚后和儿子睡觉 儿子让妈给你留个种吧 儿子妈要你的大吉吧 没开灯把小偷当老公 女儿怀孕我给姑爷解决问题 有给儿子口的吗 儿子你的真大 儿子想怎么弄就怎么弄吧 坏儿子还能在深点吗 睡着儿子顶了进来 儿子别急妈是你的小说 儿子今晚妈让你做人个够的视频 母亲和我做完跟父亲做在线阅读 高粱地里野坑头 明明有老公却想跟儿子