lightoj 1198(贪心)
2016-08-08 15:07
330 查看
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
别人都说的田忌赛马,我不会在博客上看的别人的代码,然而我没有想出来
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<string.h> #include<algorithm> using namespace std; int a[55],b[55]; int main() { int t,T=1; scanf("%d",&t); while(t--) { int n,i,j,k; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) scanf("%d",&b[i]); sort(a+1,a+n+1);sort(b+1,b+n+1); int cnt=0; int maxa=n,maxb=n; int mina=1,minb=1; for(i=1;i<=n;i++) { if(a[mina]>b[minb]) { cnt+=2; mina++;minb++; } else if(a[mina]<b[minb]) { mina++;maxb--; } else { if(a[maxa]>b[maxb]) { cnt+=2; maxa--;maxb--; } else if(a[maxa]==b[maxb]) { if(a[mina]==b[maxb]) cnt++; mina++;maxb--; } else { mina++;maxb--; } } } printf("Case %d: %d\n",T++,cnt); } return 0; }
相关文章推荐
- 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
- 【LightOJ】[1198]Karate Competition
- LightOJ - 1425 The Monkey and the Oiled Bamboo(贪心)
- LightOJ 1396 Palindromic Numbers (III)(贪心)
- codevs 1198 国王游戏 贪心
- lightoj 1166 1166 - Old Sorting 贪心
- Lightoj 1166 - Old Sorting (简单贪心)
- LightOJ 1106 Gone Fishing 贪心, DP, 堆优化 2017年1月23日
- LightOJ - 1389 Scarecrow(贪心)
- LightOJ 1189 - Sum of Factorials(贪心+阶乘)
- LightOJ 1389 - Scarecrow(贪心啊)
- lightoj 1016 - Brush (II) 贪心
- lightoj 1383 - Underwater Snipers 二分+贪心
- lightoj.1048.Conquering Keokradong(二分 + 贪心)