【LightOJ】1198 - Karate Competition(贪心 & 双端队列)
来源:互联网 发布:淘宝店铺什么是c店 编辑:程序博客网 时间:2024/05/28 06:04
点击打开题目
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
还是田忌赛马的贪心,策略和以前发的一个田忌赛马的题一样。用双端队列实现更方便一些。
传送门:点击打开链接
代码如下:
#include <cstdio>#include <algorithm>#include <cstring>#include <queue>using namespace std;#define CLR(a,b) memset(a,b,sizeof(a))int main(){int u;scanf ("%d",&u);int n;int t;int num = 1;while (u--){scanf ("%d",&n);deque<int> q1;deque<int> q2;for (int i = 1 ; i <= n ; i++){scanf ("%d",&t);q1.push_front(t);}for (int j = 1 ; j <= n ; j++){scanf ("%d",&t);q2.push_front(t);}sort (q1.begin() , q1.end());sort (q2.begin() , q2.end());int ans = 0;for (int i = 1 ; i <= n ; i++){if (q1.back() > q2.back()){ans += 2;q1.pop_back();q2.pop_back();continue;}if (q1.front() > q2.front()){ans += 2;q1.pop_front();q2.pop_front();}else{if (q1.front() == q2.back())ans++;q1.pop_front();q2.pop_back();}}printf ("Case %d: ",num++);printf ("%d\n",ans);}return 0;}
- 【LightOJ】1198 - Karate Competition(贪心 & 双端队列)
- 【Light-oj】-1198 - Karate Competition(贪心+双端队列)
- 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
- Karate Competition(贪心)
- lightoj 1198Karate Competition(田忌赛马变形)
- LightOJ 1198Karate Competition(动态规划+dp)
- Light oj 1198 Karate Competition 【贪心】
- LightOJ - 1198 Karate Competition(带权二分图)
- LOJ 1198 Karate Competition
- lightoj1198 - Karate Competition
- 机器学习5 高斯判别法
- WEB-INF目录与META-INF目录的作用
- 南方电网用电时间序列分析
- string转int/float/double、int/float/double转string、转字符串数组的方法:stoi、stringstream、scanf、to_string、sprintf
- nyoj 24 素数距离
- 【LightOJ】1198 - Karate Competition(贪心 & 双端队列)
- Android 大神们
- 史上最简单的单例模式详解
- JAVA_静态
- Android的Java混淆
- NorthWind数据库生成脚本
- Oracle 查询技巧与优化(一) 单表查询与排序
- 网易2016软件工程师笔试题-----[编程题] 奖学金(C++实现)
- [Java]struts,spring,svn杂记