【题目链接】:http://codeforces.com/contest/777/problem/B

【题意】

等价题意:

两个人都有n个数字,

然后两个人的数字进行比较;

数字小的那个人得到一个嘲讽;

问你如何搞

才能让莫里亚蒂得到的嘲讽最少;

莫里亚蒂得到的嘲讽最多;

【题解】

/*
先考虑莫里亚蒂得到最小的;
先把夏洛克的从小到大排序
然后从小到大处理夏洛克的数字;
对于夏洛克的每一个数字x
尝试用一个>=x的但是最小的数来击败它.然后这个数打上标记;
如果找不到大于等于它的数字,那么就结束;
n-i+1就是莫里亚蒂得到的最小数目;
因为夏洛克后面的数字会越来越大的; 对于让夏洛克得到最多嘲讽;
则只要把那个>=x改成>x的就好了;
i-1就是夏洛克得到的最多嘲讽个数;
*/

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e3+100; int n;
int a[N], b[N];
char s[N];
bool bo[N]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n);
scanf("%s", s + 1);
rep1(i, 1, n)
a[i] = s[i] - '0';
scanf("%s", s + 1);
rep1(i, 1, n)
b[i] = s[i] - '0';
sort(a + 1, a + 1 + n);
int ans1 = 0;
rep1(i, 1, n)
{
int mi = -1;
rep1(j,1,n)
if (!bo[j] && b[j] >= a[i])
{
if (mi == -1)
mi = j;
else
if (b[j] < b[mi])
mi = j;
}
if (mi == -1)
{
ans1 = n - i + 1;
break;
}
bo[mi] = true;
} memset(bo, false, sizeof bo);
int ans2 = n;
rep1(i, 1, n)
{
int mi = -1;
rep1(j, 1, n)
if (!bo[j] && b[j] > a[i])
{
if (mi == -1)
mi = j;
else
if (b[j] < b[mi])
mi = j;
}
if (mi == -1)
{
ans2 = i-1;
break;
}
bo[mi] = true;
}
cout << ans1 << endl;
cout << ans2 << endl;
return 0;
}

【codeforces 777B】Game of Credit Cards的更多相关文章

  1. Codeforces 777B:Game of Credit Cards(贪心)

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 546C】Soldier and Cards

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 743E】Vladik and cards

    [题目链接]:http://codeforces.com/problemset/problem/743/E [题意] 给你n个数字; 这些数字都是1到8范围内的整数; 然后让你从中选出一个最长的子列; ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. Java web开发了解

    1.什么是Java web项目? F.A.Q: 服务器 服务器,也称伺服器,是提供计算服务的设备.由于服务器需要响应服务请求,并进行处理,因此一般来说服务器应具备承担服务并且保障服务的能力.服务器的构 ...

  2. oracle-function 练习

    /* *scm_iss.test_imti_fun2 *带有输入參数的Function */ CREATE OR REPLACE FUNCTION TEST_IMTI_FUN2(P_NO IN NUM ...

  3. AbstractQueuedSynchronizer的介绍和原理分析

    简介 提供了一个基于FIFO队列,可以用于构建锁或者其他相关同步装置的基础框架.该同步器(以下简称同步器)利用了一个int来表示状态,期望它能够成为实现大部分同步需求的基础.使用的方法是继承,子类通过 ...

  4. .NetCore微服务Surging新手傻瓜式 入门教程 学习日志---结构简介(二)

    原文:.NetCore微服务Surging新手傻瓜式 入门教程 学习日志---结构简介(二) 先上项目解决方案图: 以上可以看出项目结构可以划分为4大块,1是surging的核心底层,2,3,4都可以 ...

  5. UVA 11178 - Morley's Theorem 向量

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  6. 对照jQuery和AngularJS的不同思维模

    对照jQuery和AngularJS的不同思维模 Question 如果我已经熟悉了怎样使用jQuery来开发client应用.我如今打算使用AngularJS.请描写叙述一下有那些思维模式方面的东西 ...

  7. 前端css常用的选择小汇

    要使用css对HTML页面中的元素实现一对一,一对多或者多对一的控制,这就需要用到CSS选择器.选择器就是选择器用来指定样式的作用范围. 类选择器: 类选择器在css中比较常见,首先要在普通标签中设置 ...

  8. [Swift] Add Scroll View

    import UIKit class AboutViewController : UIViewController @IBOutlet weak var scrollView: UIScrollVie ...

  9. <h2>1. mongodb介绍</h2>

    1. mongodb介绍 2. ppt下载地址 http://download.csdn.net/detail/u014285882/7807105 阅读全文 本文已收录于下面专栏: mongodb使 ...

  10. Spring的任务调度@Scheduled注解——task:scheduler和task:executor的解析

    原文地址: https://blog.csdn.net/yx0628/article/details/80873774 一个简单的Spring定时任务的 demo,全部代码见下载地址:https:// ...