【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 [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- JQuery 各节点获取函数:父节点,子节点,兄弟节点
jQuery.parent(expr) //找父元素 jQuery.parents(expr) //找到所有祖先元素,不限于父元素 jQuery.children ...
- P2P平台很赚钱么?
最近几年,搞P2P网贷和财富投资相关的金融周边公司,多了很多,楼下门店和电梯里的贷款小广告,真是多啊. 大家都去搞一件事的时候,很可能是大家都觉得这件事有利可图.但事实是,赚钱的总是少数,看到别人搞的 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- HDU 2844 Coins (多重背包计数 空间换时间)
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- 10.8 android输入系统_实战_使用GlobalKey一键启动程序
11. 实战_使用GlobalKey一键启动程序参考文章:Android 两种注册(动态注册和静态注册).发送广播的区别http://www.jianshu.com/p/ea5e233d9f43 [A ...
- [Angular2 Router] Index router
Index router as default router. import {RouterModule} from "@angular/router"; import {NotF ...
- C#判断操作系统类型
操作系统 PlatformID 主版本号 副版本号 Windows95 1 4 0 Windows98 1 4 10 WindowsMe 1 4 90 WindowsN ...
- CSS垂直居中的实现
这个问题可以说是老生常谈了,面试时经常问道,一直没整理过,这次做个系统梳理 1.利用display:table实现 从caniuse.com上查到,display:table可以兼容到IE8,以目前环 ...
- HDU 1013 Digital Roots 题解
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- js课程 2-7 for-in循环怎么使用
js课程 2-7 for-in循环怎么使用 一.总结 一句话总结:用的是in的作用加上for的作用,相当于一个组合技. 1.js中in运算符的作用是什么? 判断一个元素是否在一个集合或者对象中 1.a ...