Codeforces 777B Game of Credit Cards
B. Game of Credit Cards
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favourite n-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if n = 3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1 and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.
Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3 and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.
Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of digits in the cards Sherlock and Moriarty are going to use.
The second line contains n digits — Sherlock's credit card number.
The third line contains n digits — Moriarty's credit card number.
Output
First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.
Examples
Input
3
123
321
Output
0
2
Input
2
88
00
Output
2
0
Note
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
题目链接:http://codeforces.com/problemset/problem/777/B
分析:贪心,去比较出每个数的大小,统计其个数即可!
下面给出AC代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 bool cmp(int a,int b)
4 {
5 return a>b;
6 }
7 int main()
8 {
9 int n;
10 char a[1005];
11 char b[1005];
12 while(scanf("%d",&n)!=EOF)
13 {
14 scanf("%s%s",a,b);
15 sort(a,a+n);
16 sort(b,b+n);
17 int x=0;
18 int y=0;
19 for(int i=0,j=0;j<n;j++)
20 {
21 if(b[j]>=a[i]) i++;
22 else x++;
23 }
24 for(int i=n-1,j=n-1;i>=0;i--)
25 {
26 if(b[j]>a[i])
27 {
28 j--;
29 y++;
30 }
31 }
32 printf("%dn%dn",x,y);
33 }
34 return 0;
35 }
- fckeditor上传问题的解决
- Flash/Flex学习笔记(46):正向运动学
- 异步Socket处理的一些测试值
- .Net中DES加密的细节问题
- 分布式监控系统Zabbix--完整安装记录 -添加web页面监控
- .Net中使用带UI的OCX的方法
- 2017数据科学领域15大热门GitHub项目
- 简单分页的性能优化
- Flash/Flex学习笔记(42):坐标旋转
- 分布式监控系统Zabbix-完整安装记录 -添加端口监控
- Flash/Flex学习笔记(40):弹性运动续--弹簧
- 表格样式—粗边框细表格线
- 分布式监控系统Zabbix--完整安装记录 -添加apache监控
- Flash/Flex学习笔记(38):缓动动画
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Linux配置实现免密钥登录过程解析
- 可以提高效率的十个Linux命令别名汇总
- 基于linux命令提取文件夹内特定文件路径
- Ubuntu20.04修改ip地址的方法示例
- Linux 逻辑卷管理(LVM)使用方法总结
- Linux 下载安装VSCode 使用编程输出当前时间的方法
- 详解Linux获取线程的PID(TID、LWP)的几种方式
- Linux文件基本属性知识点总结
- Linux MySQL忘记root密码解决方案
- 如何使用iostat查看linux硬盘IO性能
- linux搭建NFS文件共享服务器的步骤详解
- Windows和Linux实现远程桌面连接
- Ubuntu19.10开启ssh服务(详细过程)
- Ubuntu 18.04更换apt-get源的方法
- 浅谈Linux环境变量文件介绍