code force 401B. Game of Credit Cards
2 seconds
256 megabytes
standard input
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 1and 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.
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.
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.
3
123
321
0
2
2
88
00
2
0
First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.
/*
贪心:田忌赛马
*/ #include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
char s[];
char m[];
int a[];
int b[];
int n;
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&n);
scanf("%s",s);
for(int i=;i<n;i++){
a[i]=s[i]-'';//大王的马
}
scanf("%s",m);
for(int i=;i<n;i++){
b[i]=m[i]-'';//田忌的马
}
// for(int i=0;i<n;i++){
// cout<<a[i]<<" ";
// }cout<<endl;
// for(int i=0;i<n;i++){
// cout<<b[i]<<" ";
// }cout<<endl; sort(a,a+n);
sort(b,b+n);
int j;
j=n-;
for(int i=n-;i>=;i--){
if(a[i]<=b[j])j--;
}
cout<<j+<<endl;
j=;
for(int i=;i<n;i++){
if(b[i]>a[j])j++;
}
cout<<j<<endl;
return ;
}
code force 401B. Game of Credit Cards的更多相关文章
- Codeforces 777B Game of Credit Cards
B. Game of Credit Cards time limit per test:2 seconds memory limit per test:256 megabytes input:stan ...
- Codeforces777B Game of Credit Cards 2017-05-04 17:19 29人阅读 评论(0) 收藏
B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Game of Credit Cards(贪心+思维)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- Game of Credit Cards
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- Codeforces 777B:Game of Credit Cards(贪心)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- pycharm debug后会出现 step over /step into/step into my code /force step into /step out 分别表示
1.debug,全部打印 2.打断点debug,出现单步调试等按钮,只运行断点前 3.setup over 调试一行代码 4.setup out 运行断点后面所有代码 5.debug窗口显示调试按钮 ...
- code forces 1173 C. Nauuo and Cards
本文链接:https://www.cnblogs.com/blowhail/p/10990833.html Nauuo and Cards 原题链接:http://codeforces.com/con ...
- 【Code Force】Round #589 (Div. 2) D、Complete Tripartite
题目链接 大致题意 把一个图分成三块,要求任意两块之间是完全图,块内部没有连线 分析 首先根据块内没有连线可以直接分成两块 假定点1是属于块1的,那么所有与点1连接的点,都不属于块1:反之则是块1的 ...
- code force 424 A - Office Keys
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
随机推荐
- Spark任务流程笔记
Spark学习笔记总结 02. Spark任务流程 1. RDD的依赖关系 RDD和它依赖的父RDD(s)的关系有两种不同的类型,即窄依赖(narrow dependency)和宽依赖(wide de ...
- Split分割字符串
第一种方法:打开vs.net新建一个控制台项目.然后在Main()方法下输入下面的程序. string s="abcdeabcdeabcde"; string[] sArray=s ...
- Nginx学习——Nginx基本配置
1.Nginx的配置文件总览 Nginx配置文件详解 : http://www.cnblogs.com/hunttown/p/5759959.html nginx.conf 基本格式: worker_ ...
- MySQL锁和事务(一):InnoDB锁(MySQL 官方文档粗翻)
// 写在前面,实际上,数据库加锁的类型和范围受到多种因素的影响,例如数据库隔离等级,SQL语句,是否使用主键.索引等等.可以查看博文: http://www.cnblogs.com/zhaoyl/p ...
- Qt全局宏和变量
1. Qt 全局宏定义 Qt版本号: QT_VERSION : (major << 16) + (minor << 8) + patch 检测版本号: QT_VERSION ...
- Java的基本程序设计结构【2】
注释 与大多数程序设计语言一样,Java 中的注释也不会出现在可执行程序中.因此,可以在源程序中根据需要添加任意多的注释,而不必担心可执行代码会膨胀.在Java 中,有三种书写注释的方式. 最常用的方 ...
- 浅谈PHP7的新特性
我以前用过的php的最高版本是php5.6.在换新工作之后,公司使用的是PHP7.据说PHP7的性能比之前提高很多.下面整理下php7的新特性.力求简单了解.不做深入研究. 1.变量类型声明 函数的参 ...
- Linux: 查看软件安装路径
一. Which 命令 Shell 的which 命令可以找出相关命令是否已经在搜索路径中. 如: [root@localhost ~]# which gcc /usr/bin/gcc ...
- 机器学习算法实践:Platt SMO 和遗传算法优化 SVM
机器学习算法实践:Platt SMO 和遗传算法优化 SVM 之前实现了简单的SMO算法来优化SVM的对偶问题,其中在选取α的时候使用的是两重循环通过完全随机的方式选取,具体的实现参考<机器学习 ...
- SpringMVC 基本概念
DispatcherServlet:前端控制器,解释用户请求,通过HandlerMapping查找对应Handler处理请求,调用ViewResolve回填页面,DispatcherServlet在W ...