【codeforces 777B】Game of Credit Cards
【题目链接】: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的更多相关文章
- Codeforces 777B:Game of Credit Cards(贪心)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 546C】Soldier and Cards
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 743E】Vladik and cards
[题目链接]:http://codeforces.com/problemset/problem/743/E [题意] 给你n个数字; 这些数字都是1到8范围内的整数; 然后让你从中选出一个最长的子列; ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- 初学者路径规划 | 人生苦短我用Python
纵观编程趋势 人生苦短,我用Python,比起C语言.C#.C++和JAVA这些编程语言相对容易很多.Python非常适合用来入门.有人预言,Python会成为继C++和Java之后的第三个主流编程语 ...
- [React & Debug] Quick way to debug Stateless component
For example we have the following code: const TodoList = (props) => ( <div className="Tod ...
- express,中间件(body-parser),req.body获取不到参数(含postman发请求的方法)
问题描述: 最近在做毕设,express 里边的中间件(body-parser)失效,req.body获取不到任何值,req.query能获取到值.一开始加body-parser中间件是有用的,直到昨 ...
- log4j 2.x 版本的 properties 配置
#用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,会看到log4j2内部各种详细输出status = debugdest = errname = PropertiesConf ...
- 每日技术总结:filter(),Bscroll
前言: 这是一个vue的电商项目,使用express后端提供数据. 1.filter()函数. 事情是这样的.我从数据库拿到了所有分类数据. 分类有三个等级.父类,子类,孙类这样.但它们都在同一张表里 ...
- 手把手教你----MyEclipse中 配置 Tomcat
电脑上配置Tomcatserver 安装Tomcat并配置环境变量 測试是否配置成功 MyEclipse中配置Tomcat 想要开发Java Web的程序.首先在MyEclipse中必须配置Tomca ...
- php 面试题一(看视频的学习量比网上瞎转悠要清晰和明了很多)(看视频做好笔记)(注重复习)
php 面试题一(看视频的学习量比网上瞎转悠要清晰和明了很多)(看视频做好笔记)(注重复习) 一.总结 1.无线分类的本质是树(数据结构)(数的话有多种储存结构可以实现,所以对应的算法也有很多),想到 ...
- 20、RTC驱动程序
drivers\rtc\rtc-s3c.c s3c_rtc_init platform_driver_register s3c_rtc_probe rtc_device_register(" ...
- [Swift] Add Scroll View
import UIKit class AboutViewController : UIViewController @IBOutlet weak var scrollView: UIScrollVie ...
- <p><img src="http://img.blog.csdn.net/20150823142545135?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt=""></p>
/* 实现功能:用顺序表实现栈的各种操作 编译环境:Windows 64b,vc6.0 日期: 2015/7/20 作者:wtt561111 */ #define stack_max_num 10 # ...