Game of Credit Cards (贪心)_game of credit cardshdu-程序员宅基地

题目链接---Game of Credit Cards

                              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 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 123 and get no flicks at all, or he can name 23 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.

Example
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.


题意:就是一些卡片,每个卡片上有几个数字,现在有SherlockMoriarty 两个人在比较这些卡片上的数字大小,小的数字需要接受惩罚,Sherlock的卡片顺序是固定的,Moriarty的卡片顺序可以随意变动,Moriarty的最小接受惩罚次数是多少,Sherlock最大惩罚对方的次数是多少。

题解:贪心解决

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
     return a>b;
}
int main()
{
     int n;
     char a[1005];
     char b[1005];
     while(scanf("%d",&n)!=EOF)
     {
         scanf("%s%s",a,b);
         sort(a,a+n);
         sort(b,b+n);
         int x=0;
         int y=0;
         for(int i=0,j=0;j<n;j++)
         {
             if(b[j]>=a[i]) i++;
             else x++;
         }
         for(int i=n-1,j=n-1;i>=0;i--)
         {
             if(b[j]>a[i])
             {
                 j--;
                 y++;
             }
         }
         printf("%d\n%d\n",x,y); 
     }
return 0;
 }

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/NSSWTT/article/details/79393718

智能推荐

Qt中如何将QComboBox中的选项StringItem与数值内联binding_qt combobox显示数值和实际值怎么绑定-程序员宅基地

文章浏览阅读501次。Qt中如何将QComboBox中的选项StringItem与数值内联binding开发文档中有两种方法第一种:第二种:这里介绍第二种(我认为更简单的一种)就用我目前做的一个小项目来说吧我的combo box中有各种各样的运动,每种运动自动内联着它所对应的一个小时所消耗的卡路里(int)consume::consume(QWidget *parent) : QDialog(parent), ui(new Ui::consume){ ui->setupUi(_qt combobox显示数值和实际值怎么绑定

最新大猿人中控充值系统 免授权学习版 支持公众号H5、分销等功能_猿人充值系统 3.2 漏洞-程序员宅基地

文章浏览阅读1.5k次。简介:最新大猿人中控充值系统 免授权破解版 支持公众号H5、分销等功能功能简介:大猿人中控系统目前是市面上用的最多的电话费充值中控系统,支持代理分销、公众号H5、API接口对接等功能,也是目前最完善的一款中控系统,前端全开源,已破解免授权!配置环境:php7.3 + Redis搭建教程:1、首先吧大猿人中控系统压缩包上传到服务器内进行解压,然后吧数据库文件导入数据库内2、修改/application/database.php 文件进行配置链接数据库。_猿人充值系统 3.2 漏洞

创建异形窗口[3]-程序员宅基地

文章浏览阅读81次。为什么80%的码农都做不了架构师?>>> ..._gtk3 异形窗口

C语言:验证下列矩阵是否为魔方阵。魔方阵是每一行、每一列、主副对角线上的元素之和都是相等的矩阵。-程序员宅基地

文章浏览阅读2.6k次。#include <stdio.h>#include <string.h>#include <string.h>int main(void){ int a[5][5] = {17,24,1,8,15, 23,5,7,14,16, 4,6,13,20,22, 10,12,19,21,3, 11,18,25._验证下列矩阵是否为魔方阵。魔方阵是每一行、每一列、主副对角线上的元素之和都是

Django疫情返乡人员管理系统-11411,计算机毕业设计开题选题+程序定制+论文书写+答辩ppt书写-原创(题目+编号)的定制程序-程序员宅基地

文章浏览阅读51次。免费领取项目源码,请关注赞收藏并私信博主,谢谢-本课题研究的疫情返乡人员管理系统,主要功能模块包括:防疫须知、疫情用品、返乡报备、用户反馈管理等,主要是主要采取Mysql作为后台数据的主要存储单元,运用软件工程原理和开发方法,采用Python的Django技术构建的,实现了系统的全部功能。本次报告,首先分析了研究的背景、作用、意义,为研究工作的合理性打下了基础。

oracle序列中cache和nocache-程序员宅基地

文章浏览阅读1.1k次。首先我这篇博客的内容是我不知道oracle里的 cache 是什么,结果越查越多。。。“序列的cache通常为 20,但在需要依据序列值判断创建的先后顺序时必须是 NOCACHE”,关于这句话,是公司的数据库规范里提到的一句话,但是我感觉nocache会导致的问题好像还不少,所以我很纠结,但是除了根据序列值判断创建的先后顺序外,还有其他的靠谱的方式来判断先后顺序吗?难道入库时间不可以吗..._数据库中的nocache是什么意思

随便推点

您绝对不能错过的 10 个 OKR 示例!_优秀的okr案例-程序员宅基地

文章浏览阅读429次,点赞6次,收藏8次。在此基础上,制定团队 OKR,它可以是产品层面的或部门层面的,但它们会融入组织的目标中。使用 OKR 方法的一个巨大好处是,它可以针对不同的部门和团队进行细分, 以便整个公司追求相同的组织目标,但利用特定的关键结果。如果您没有达到 100% 的关键结果,您仍然应该为实现这一目标所付出的努力感到自豪,评估是否需要进行更改,并重新调整下一个周期的目标和关键结果。令人惊讶的是,伦敦商学院进行的一项研究显示,在接受调查的 11,000 名高级管理人员中,只有三分之一能够列出他们公司的三大优先事项。_优秀的okr案例

HDU 5350(MZL's munhaff function-哈夫曼树)_禎痲霤攷 hdu-程序员宅基地

文章浏览阅读2.1k次。MZL's munhaff functionTime Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 230 Accepted Submission(s): 133Problem DescriptionMZL is _禎痲霤攷 hdu

AndroidStudio4.1 自定义模板_android studio 4.1 自定义模板-程序员宅基地

文章浏览阅读1.3k次。AndroidStudio4.0之前,可以在template的文件夹里使用freemarker的自定义模板,可以在AndroidStudio的文件夹中,随意的添加适合自己的自定义模板,之前鸿洋大神的文章已经有来详细的介绍(https://blog.csdn.net/lmj623565791/article/details/51592043)。但是从4.1版本开始提供新的方式,Geminio,用Kotlin的形式编写新的template,而且需要使用插件的形式,才能使用自定义的模板,摸索了好几天,终于解决了_android studio 4.1 自定义模板

微信小程序云开发-酒店点餐类系统,附带(node.js在widows环境下的配置过程)_云开发可以做扫码类么-程序员宅基地

文章浏览阅读3.2k次,点赞3次,收藏11次。前些日子,帮一个学生做了一个毕业设计,是关于酒店点餐的微信小程序,现在整理一下过程。本款小程序是基于微信云开发的,现在做微信小程序的一大方便是:微信给大家提供了免费空间(云开发),对于不想花钱去租用服务器和域名的小伙伴儿来说,这无疑是一大喜事! 本款小程序非常适合商城类小程序的二次开发或是学习商城类小程序最佳的一个案例。废话不多说,直接上图:小程序..._云开发可以做扫码类么

jq使用ajax报错404,jQuery中ajax错误调试分析-程序员宅基地

文章浏览阅读1.8k次。jQuery中把ajax封装得非常好。但是日常开发中,我偶尔还是会遇到ajax报错。这里简单分析一下ajax报错一般的jQuery用法如下,ajax通过post方式提交"汤姆和老鼠"这段数据到xxx.php文件中。成功后则打印返回的数据,失败则打印错误原因。$.ajax({url:"xxx.php",type:"post",datatype:"json",data:{"cat":"tom","mo..._jquery ajax保存数据到后端flask,出现404not found错误

HDU 1587 Flowers 解题报告_2019 flowers acm-程序员宅基地

文章浏览阅读1.3k次。动态规划 完全背包_2019 flowers acm