【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 [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- PythonNET网络编程4
本地套接字 Linux 文件 b(块设备文件) c(字符设备文件) d(目录) -(普通文件) l(链接) s(套接字) p(管道) 作用:用于本地不同的程序间进行通信 创建流程 创建本地套接字 so ...
- 【 Codeforces Round #430 (Div. 2) A 】 Kirill And The Game
[链接]点击打开链接 [题意] 水题 [题解] 枚举b从x..y看看k*i是不是在l..r之间就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <cstdio> ...
- 洛谷——P1046 陶陶摘苹果
https://www.luogu.org/problem/show?pid=1046 题目描述 陶陶家的院子里有一棵苹果树,每到秋天树上就会结出10个苹果.苹果成熟的时候,陶陶就会跑去摘苹果.陶陶有 ...
- Centos 6 vnc 部署
一.安装gnome桌面环境 yum groupinstall -y 'X Window System' yum groupinstall -y "Desktop" 二.部署vnc ...
- report_timing_requirement
report_timing_requirement -ignored 会报告set_faults_paths,set_multi_path等
- DB2学习总结(1)——DB2数据库基础入门
DB2的特性 完全Web使能的:可以利用HTTP来发送询问给服务器. 高度可缩放和可靠:高负荷时可利用多处理器和大内存,可以跨服务器地分布数据库和数据负荷:能够以最小的数据丢失快速地恢复,提供多种备份 ...
- tomcat 服务形式检测
http://blog.chinaunix.net/uid-20449851-id-2369842.html
- Linux下的lds链接脚本简介(二)
七. SECTIONS命令 SECTIONS命令告诉ld如何把输入文件的sections映射到输出文件的各个section: 如何将输入section合为输出section; 如何把输出section ...
- UVA 10943 - How do you add? 递推
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UIScrollView(滚动试图)
UIScrollView(滚动试图) 1.简介 为什么有UISCrollView: 在iOS开发中,由于移动设备的屏幕大小有限,所以不能像PC一样显示很多内容,因此当手机屏幕需要展示的内容较多超出一个 ...