LightOj 1198 田忌赛马/贪心
来源:互联网 发布:人工智能美女机器人 编辑:程序博客网 时间:2024/05/16 13:23
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 <iostream>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <map>#include <vector>#define MM(s,q) memset(s,q,sizeof(s))#define INF 0x3f3f3f3f#define MAXN 1005#define Lchild id<<1#define Rchild (id<<1)+1#define ll long long#define FILE freopen("data.in","r",stdin)using namespace std;int main() { int T, n, k, icase = 1, A[100], B[100]; cin >> T; while (T--) { cin >> 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); sort(B, B + n); int la = 0, lb = 0, ra = n - 1, rb = n - 1, ans = 0; while (la <= ra) { // cout << A[ra] << " " << B[rb] << endl; if (A[ra] > B[rb]) { ans += 2; ra--, rb--; } else if (A[ra] < B[rb]) { la++, rb--; } else if (A[ra] == B[rb]) { if (A[la] > B[lb]) la++, lb++, ans += 2; else if (A[la] == B[rb]) ans += 1, la++, rb--; else la++, rb--; } } printf("Case %d: %d\n", icase++, ans); }}
- LightOj 1198 田忌赛马/贪心
- LightOJ 1198 (田忌赛马 类似)
- lightoj 1198Karate Competition(田忌赛马变形)
- 【贪心DP】田忌赛马
- poj2287-田忌赛马贪心
- 贪心算法 田忌赛马
- 田忌赛马 简单贪心
- nyoj364田忌赛马【贪心】
- 田忌赛马(贪心)
- nyoj364 田忌赛马 贪心
- 贪心算法--田忌赛马
- HDU1052:田忌赛马《贪心》
- 田忌赛马-贪心正确性证明
- 2287 poj 田忌赛马,贪心
- NYOJ 364 田忌赛马 (贪心)
- hdu1052 田忌赛马 贪心正确性证明
- 贪心算法之田忌赛马
- POJ2287--贪心(田忌赛马)
- 对负数取余的操作
- 突然发现proteus闪退的一些原因!!!
- C++异常
- 数值作业:Crout克洛特分解法之C语言代码
- 归并排序详解
- LightOj 1198 田忌赛马/贪心
- 5-30 字符串的冒泡排序 (20分)
- 对于JSP几大对象的一点认识
- python中find()的用法
- linux内核添加新的模块
- Java main方法的参数
- hpuoj1339 容斥原理变形
- poj 3253 优先队列
- MyEclipse debug 断点不能调试 ,unable to install breakpoint in ...... 解决办法