Game of Credit Cards(贪心+思维)
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, 3and 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.
思路:两个进行排序,然后看自己的去比别人的大,如果M不挨打,那他一定要大于等于另一个,都要从小的遍历 ,然后标记,不然下次还会比,另一个打的最多也差不多的思路
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<set>
#include<cmath>
typedef long long ll;
using namespace std;
char a[1005];
char b[1005];
int s1[1005];
int s2[1005];
int vis[1005];
int main() {
int n;
cin>>n;
scanf("%s",a);
scanf("%s",b);
for(int t=0; t<n; t++) {
s1[t]=a[t]-'0';
s2[t]=b[t]-'0';
}
sort(s1,s1+n);
sort(s2,s2+n);
int s=n;
for(int t=0; t<n; t++) {
for(int j=0; j<n; j++) {
if(s2[t]>=s1[j]&&vis[j]==0) {
s--;
vis[j]=1;
break;
}
}
}
memset(vis,0,sizeof(vis));
int ss=0;
int k=0;
for(int t=0; t<n; t++) {
for(int j=0; j<n; j++) {
if(s2[t]>s1[j]&&vis[j]==0) {
ss++;
vis[j]=1;
break;
}
}
}
cout<<s<<endl;
cout<<ss<<endl;
return 0;
}
Game of Credit Cards(贪心+思维)的更多相关文章
- codeforces 893D Credit Card 贪心 思维
codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...
- CodeForces - 777B Game of Credit Cards 贪心
题目链接: http://codeforces.com/problemset/problem/777/B 题目大意: A, B玩游戏,每人一串数字,数字不大于1000,要求每人从第一位开始报出数字,并 ...
- Codeforces 777B:Game of Credit Cards(贪心)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- code force 401B. Game of Credit Cards
B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 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 ...
- Mike and distribution CodeForces - 798D (贪心+思维)
题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
随机推荐
- Docker学习笔记_Dockerfile基本知识
Dockerfile由一行行命令语句组成,并支持以#开头的注释行. 1.编写一个Dockerfile文件 创建一个空的Docker工作目录,进入该目录,使用sudo vim Dockerfile指令新 ...
- Linux内核的特征
Linux内核的特征 Linux是个人计算机和工作站上的Unix类操作系统.但是,它绝不是简化的Unix.相反,Linux是强有力和具有创新意义的Unix类操作系统.它不仅继承了Unix的特征,而且在 ...
- Solidity transfer vs send 区别
原文地址: https://ethereum.stackexchange.com/questions/19341/address-send-vs-address-transfer-best-pract ...
- Luogu 3899 [湖南集训]谈笑风生
BZOJ 3653权限题. 这题方法很多,但我会的不多…… 给定了$a$,我们考虑讨论$b$的位置: 1.$b$在$a$到根的链上,那么这样子$a$的子树中的每一个结点(除了$a$之外)都是可以成为$ ...
- 利用osmosis导出osm城市数据
转载(未测试) 方法核心就是利用osmosis的导出指定功能,即是从大范围导出小范围的基本用例. 我们只需要知道我们所需要提取的城市的经纬度范围, 例如广州市的经纬度范围是北纬22.26~23.56度 ...
- ShopNc登录验证码
- html5操作类名API——classlist
tagNode.classList.add('123'); // 添加类 tagNode.classList.remove('bbb'); // 删除类 tagNode.classList.toggl ...
- HTTP文件上传插件开发文档-ASP
版权所有 2009-2016 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webplug/http-u ...
- spring的一些配置和重要的接口和类
spring的配置文件 通常是applicationContext.xml(具体的bean配置会在后面内容中详解) setter方法注入: <property name=“” value=“ja ...
- 那些年我们追过的SQL
SQL是大学必修课程之一二维表结构,看着就是一种美感. 针对近期感情,聊一聊,在平时容易犯的一个错误,看看你是不是中枪了. 我们还是选用传统的student表(请不要考虑表的结构是否合理)ID ...