Codeforces 777B 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 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>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n;
char a[];
char b[];
while(scanf("%d",&n)!=EOF)
{
scanf("%s%s",a,b);
sort(a,a+n);
sort(b,b+n);
int x=;
int y=;
for(int i=,j=;j<n;j++)
{
if(b[j]>=a[i]) i++;
else x++;
}
for(int i=n-,j=n-;i>=;i--)
{
if(b[j]>a[i])
{
j--;
y++;
}
}
printf("%d\n%d\n",x,y);
}
return ;
}
Codeforces 777B Game of Credit Cards的更多相关文章
- 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 ...
- 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
[题目链接]:http://codeforces.com/contest/777/problem/B [题意] 等价题意: 两个人都有n个数字, 然后两个人的数字进行比较; 数字小的那个人得到一个嘲讽 ...
- 【贪心】【multiset】 Codeforces Round #401 (Div. 2) B. Game of Credit Cards
对第一个人的排序,然后从小到大处理,对第一个人的每枚卡片,从第二个人的卡片中选择一个大于等于它的最小的,否则选择一个当前剩下的最小的,这样可以保证负场最少. 如果选择的改成大于它的最小的,就可以保证胜 ...
- 【codeforces 546C】Soldier and Cards
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- JavaWeb 例子 JDBC+JSP登陆注册留言板
注册页面: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...
- bzoj 2302: [HAOI2011]Problem c
Description 给n个人安排座位,先给每个人一个1~n的编号,设第i个人的编号为ai(不同人的编号可以相同),接着从第一个人开始,大家依次入座,第i个人来了以后尝试坐到ai,如果ai被占据了, ...
- C#中Abstract和Virtual[转载]
原文:http://www.cnblogs.com/blsong/archive/2010/08/12/1798064.html 在C#的学习中,容易混淆virtual方法和abstract方法的使用 ...
- 【二十七】php之绘图技术(gd、jpgraph、短信随机验证码)
1.绘图技术(GD库) 注意:使用该库,php.ini文件中的extension=php_gd2.dll必须是开启状态,不然无法使用 图片格式:目前网站开发常见的图片格式有gif,jpg/jpeg,p ...
- Sublime Text 2 Plugin Installation
For Package Control installation, see the Installation Guide. To install Emmet(ex Zen Coding), do ...
- windows下查看端口占用情况及关闭相应的进程
经常,我们在启动应用的时候发现系统需要的端口被别的程序占用,如何知道谁占有了我们需要的端口,很多人都比较头疼,下面就介绍一种非常简单的方法. 例如:需要查看9001端口被谁占用,并将其进程强制关闭 在 ...
- 【liferay】3、liferay 添加spring支持
1.添加对应的spring的jar 地址:https://spring.io/projects 选中springframework 进入git源码的地方,看简介 我们需要编译好的jar 当然也可以自己 ...
- oracle 导入 dmp
执行命令 imp his/his@orcl File=/home/oracle/core_his50_common.dmp FULL=Y
- C# System.Windows.Forms.NumericUpDown 控件全选其中文字
num_length.Focus(); UpDownBase updbText = (UpDownBase)num_length; ...
- spring的基本使用
Spring的基本使用ioc,今天主要给大家说明了解决强耦合的联系,并且,注入的基本使用 Java里面的强耦合并且讲了spring是如何解决强耦合的第一种方式使用工厂模式,用的是反射,第二种方式是sp ...