题干:

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.

题目大意:

夏洛克和她玩起了弹脑壳的游戏。。。他们都拿到n个数字,并且夏洛克只能按照顺序念,她耍赖,可以挑着念(改变顺序)。然后,对于他们每一次念的数字,数字大的人可以给数字小的人一个脑瓜崩。问狡猾的她少可以被弹几次,&最多可以弹夏洛克几次?

解题报告:

都是从小到大同序排序,然后挨个比较,类似田忌赛马,所以叫田忌赛马贪心。(从大到小亦可解?)

ac代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1000+5];
int b[1000+5];int main()
{int n;int ans1=0,ans2=0;cin>>n;for(int i = 0; i<n; i++) {scanf("%1d",&a[i]);}for(int i = 0; i<n; i++) {scanf("%1d",&b[i]);}
//  for(int i = 0; i<3; i++) {
//      printf("%d   %d\n",a[i],b[i]);
//  }sort(a,a+n);sort(b,b+n);int i=0,j=0;//a[i],b[j]对应 //解ans1 while(i<n&&j<n) {if(b[j]>=a[i]) {i++;j++;ans1++;}else if(b[j]<a[i]){j++;}}ans1=n-ans1;i=0;j=0;//解ans2 while( i < n && j < n) {if(b[j]>a[i]) {ans2++;i++;j++;}if(b[j]<=a[i]) {j++;}}printf("%d\n%d",ans1,ans2);return 0 ;} 

双端队列ac

#include<cstdio>
#include<queue>
#include<deque>
#include<algorithm>
using namespace std;
int main()
{char str1[1000+11],str2[1000+11];int a,b,n;while(~scanf("%d",&n)){deque<int> q1,q2;deque<int> s1,s2;scanf("%s %s",str1,str2);for(int i=0;i<n;i++){a=str1[i]-'0';q1.push_back(a);b=str2[i]-'0';q2.push_back(b);  }sort(q1.begin() ,q1.end() );sort(q2.begin() ,q2.end() );int k1,k2,v1,v2;int num1=n,num2=0;for(int i=1;i<=n;i++){k1=q1.back() ;k2=q2.back() ;if(k2>k1){num2++;s1.push_back(k1);s2.push_back(k2);q1.pop_back() ;q2.pop_back() ;continue;  }v1=q1.front() ;v2=q2.front() ;if(v2>v1){num2++;s1.push_back(v1);s2.push_back(v2);q1.pop_front() ;q2.pop_front() ;  }else{s1.push_back(k1);s2.push_back(v2);q1.pop_back() ;q2.pop_front() ;  }}sort(s1.begin() ,s1.end() );sort(s2.begin() ,s2.end() );for(int i=1;i<=n;i++){if(s2.back() >=s1.back() ){num1--;s1.pop_back() ;s2.pop_back() ;continue;}v1=s1.front() ;v2=s2.front() ;if(v2>=v1){num1--;s1.pop_front() ;s2.pop_front() ;}else{s1.pop_back() ;s2.pop_front() ;}}printf("%d\n%d\n",num1,num2);}return 0;} 

cf#401(Div. 2)B. Game of Credit Card(田忌赛马类贪心)相关推荐

  1. CF 546 div.2 D. Nastya Is Buying Lunch(思维+贪心)

    为数不多的纯靠自己想出来的DIV2 D题 题意是 给出一个排好的队列,以及m个可交换的操作(u,v) :当u在v的前面时,u和v可直接交换位置 问最后一个人(编号Pn)最多可以向前几个位置. 在正式解 ...

  2. CF #366(div.2) C 模拟,思维

    CF #366(div.2)  C.  Thor 题意:一个手机n个联系人,有q个操作.每次给出ty和ai,如ty==1,表示收到ai的一条信息:如ty==2,表示将ai发的信息都看掉:如ty==3, ...

  3. CF #371 (Div. 2) C、map标记

    1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...

  4. cf #823 Div.2(A~C)

    Cf #823 Div.2 文章目录 Cf #823 Div.2 [A. Planets](https://codeforces.com/contest/1730/problem/A) [B. Mee ...

  5. cf #818 Div.2(A~C)

    Cf #818 Div.2 文章目录 Cf #818 Div.2 [A. Madoka and Strange Thoughts](https://codeforces.com/contest/171 ...

  6. CF #683 div.2

    CF #683 div.2 目前 ABCD A. Add Candies B. Numbers Box C. Knapsack D. Catching Cheaters 结尾 A. Add Candi ...

  7. CF#764(div.3A~D)dp进阶

    CF#764(div.3A~D)&&dp进阶 CF#764(div.3) Problem - A - Codeforces 题意 一个数列,每次操作可以使这个数列中的任何数加1,问最少 ...

  8. CF #764 Div.3(B ~D)

    CF #764 Div.3 B题 Make AP 给定a b c 使其中一个数 乘 任意正整数m 问是否能构成成差数列 我们可以想到等差数列的性质 2b=a+c2b = a + c 2b=a+c 思路 ...

  9. cf #825 Div.2(A~C2)

    Cf #825 Div.2 文章目录 Cf #825 Div.2 [A. Make A Equal to B](https://codeforces.com/contest/1736/problem/ ...

最新文章

  1. linux fcntl注销信号,fcntl · Linux C API 参考手册 · 看云
  2. 计算机控制实验教程,新)《计算机控制技术》实验教程.doc
  3. JavaScript中的交互式网页/事件处理
  4. 微信小程序的特点是什么?
  5. [python]python pandas 模块
  6. Python编程从入门到实践学习内容包含哪些?
  7. 单片机仿真软件Proteus Pro 8.9版本License过期
  8. NSString NSCFString isMemberOfClass 遇到的相关的问题
  9. week15-作业题--字符串(hash、字典树、KMP)
  10. 国家c语言计算机二级,国家计算机二级考试 C语言基本知识.pdf
  11. B站学习法之深度学习笔记一
  12. svg图片如何引入vue
  13. wordpress主题免费- wordpress插件以及主题下载
  14. css 唤醒qq聊天,移动端唤起QQ聊天
  15. Desktop Duplication API(桌面拷贝API)
  16. 【2022/1/12】think-swoole使用教程
  17. 几个命令查看ELF文件的“秘密”
  18. 安装教程之JDK下载与安装
  19. 国家超级计算机 甘霖,国家超级计算无锡中心主任助理甘霖:让“中国超算”扬威世界...
  20. matplotlib画各种图的方法(2)

热门文章

  1. [Leetcode][第410题][JAVA][分割数组的最大值][动态规划][二分]
  2. [Leetcode]第[43]题[JAVA][字符串相乘][字符串相加]
  3. java验证码的代码_java实用验证码的实现代码
  4. qt支持Linux下word导出么,qt怎么实现保存到Word
  5. 电脑二维码怎么扫描_扫描模组方案是如何满足多种应用场景需求?
  6. linux 取出字符中数字,使用awk提取字符串中的数字或字母
  7. linux内核 频率,Linux内核中CPU主频和电压调整 (三)
  8. mySQL数据库中的备份代码_MySQL中的备份数据库
  9. 修改数据包欺骗服务器,Fiddler协议捕获编辑工具与Session欺骗原理详解
  10. php进入文件目录,php文件目录操作