lightoj 1198 - Karate Competition 【贪心】
来源:互联网 发布:疯狂联盟座狼升级数据 编辑:程序博客网 时间:2024/05/21 06:37
题目链接:lightoj 1198 - Karate Competition
1198 - Karate Competition
PDF (English) Statistics Forum
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 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
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
题意:模拟田忌赛马,同水平得一分,反之得两分。
AC代码:
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;typedef long long LL;const int MAXN = 1e5 +10;const int MOD = 1e6 + 7;int a[60], b[60];int main(){ int t, kcase = 1; scanf("%d", &t); while(t--) { int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for(int i = 1; i <= n; i++) { scanf("%d", &b[i]); } sort(a+1, a+n+1); sort(b+1, b+n+1); int Maxa = n, Mina = 1; int Maxb = n, Minb = 1; int ans = 0; for(int i = 1; i <= n; i++) { if(a[Mina] > b[Minb]) { ans += 2; Mina++; Minb++; } else if(a[Mina] < b[Minb]) { Mina++; Maxb--; } else { if(a[Maxa] > b[Maxb]) { ans += 2; Maxa--; Maxb--; } else if(a[Maxa] == b[Maxb]) { if(b[Maxb] == a[Mina]) { ans += 1; } Mina++; Maxb--; } else { Mina++; Maxb--; } } } printf("Case %d: %d\n", kcase++, ans); } 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
- python中‘对象’
- 从嵌套表达式谈抽象语法树(AST)到平台无关中间指令(IR)的翻译过程(线性化)
- C++第4次实验
- IOS学习 网络HTTP Get和Post请求与登录界面加密 涉及按钮边框圆角与颜色设置
- 电话监听器
- lightoj 1198 - Karate Competition 【贪心】
- IOS App常用界面结构解析,让开发更简单
- SAR成像学习(三)距离方向成像matlab代码解析 1
- 四 单例模式
- leetcode刷题8. String to Integer (atoi)
- ThreadLocal类源码解析
- java---序列六(合并流)SequenceInputStream ——对多个流进行合并
- 致自己
- 开发工具