light oj贪心
来源:互联网 发布:广西驰程网络办公系统 编辑:程序博客网 时间:2024/05/17 21:45
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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
#include<stdio.h>#include<algorithm>using namespace std;int a[1100],b[1100];int main(){int t,n,k=1;scanf("%d",&t);while(t--){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);sort(b,b+n);int maxa=n-1,mina=0;int maxb=n-1,minb=0;int ans=0,sum=0;while(ans<n){if(a[mina]>b[minb]){mina++;minb++;sum=sum+2;ans++;}else {if(a[maxa]>b[maxb]){sum+=2;maxa--;maxb--;ans++;}else if(a[mina]==b[maxb]){mina++;maxb--;sum=sum+1;ans++;}else if(a[mina]<b[maxb]){mina++;maxb--;ans++;}}}printf("Case %d: %d\n",k++,sum);}return 0;}不知道下面这种做法怎么错了(>﹏<)运行是对的呀!!
#include<cstdio>#include<algorithm>using namespace std;bool cmp(int a,int b){return a>b;}int main(){int n,m,a[55],b[55],c[55];scanf("%d",&n);int w=1;while(n--){scanf("%d",&m);for(int i=0;i<m;i++)scanf("%d",&a[i]);sort(a,a+m,cmp);for(int i=0;i<m;i++)scanf("%d",&b[i]);sort(b,b+m,cmp);int sum=0,count=0;if(a[0]>b[m-1]){for(int j=0;j<m;j++){if(a[0]>b[j]){count++;}}int k=0;for(int i=m-count;i<m;i++)c[k++]=b[i];for(int i=0;i<m-count;i++)c[k++]=b[i]; for(int i=0;i<m;i++){if(a[i]>c[i])sum=sum+2;else if(a[i]==c[i]) sum+=1; else sum=sum;}}else if(a[0]==b[m-1]) sum=1;elsesum=0;printf("Case %d: %d\n",w++,sum);}return 0;}
- light oj贪心
- Light oj 1198 Karate Competition 【贪心】
- 【Light-oj】-1198 - Karate Competition(贪心+双端队列)
- LIGHT OJ 1189 - Sum of Factorials【贪心+递归】
- light oj 1189 - Sum of Factorials (阶乘+贪心)
- light oj 1198 贪心算法或KM算法
- light oj 1198 贪心算法或KM算法
- light oj
- light oj
- Light OJ
- Light OJ
- HDU1687 Lucky Light 【贪心】
- Light OJ 1000
- Light OJ 1001
- Light OJ 1008
- Light OJ 1022
- Light OJ 1015
- Light OJ 1042
- 安卓集训营第四天---JAVA基础数组和排序,枚举,内部类
- URLEncoder和URLDecoder实现转码和解码
- 北斗得与失(1-二次编码的缺点)
- Linux -- bash
- codevs 3143 二叉树的序遍历
- light oj贪心
- 新闻客户端功能类集合
- Uva540 队列与map
- 2015-2016ACM-ICPC NEER northern-subregional-contest E Easy Arithmetic 思维、模拟
- 内部类的详解
- Anroid优化(二)_内存优化
- 简陋自写intList--双色球实例
- linux学习之硬盘的存储原理和内部架构
- Aizu 2224 (并查集 Save you cat )