对第一个人的排序,然后从小到大处理,对第一个人的每枚卡片,从第二个人的卡片中选择一个大于等于它的最小的,否则选择一个当前剩下的最小的,这样可以保证负场最少。

如果选择的改成大于它的最小的,就可以保证胜场最多。

用multiset处理。

#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
typedef pair<int,int> Point;
Point c[1010];
multiset<int>S,tS;
typedef multiset<int>::iterator ITER;
int n,ans;
char a[1010],b[1010],d[1010];
int main()
{
freopen("b.in","r",stdin);
scanf("%d%s%s",&n,a+1,b+1);
for(int i=1;i<=n;++i)
{
c[i].first=a[i]-'0';
c[i].second=i;
}
for(int i=1;i<=n;++i)
S.insert(b[i]-'0');
tS=S;
sort(c+1,c+n+1);
for(int i=1;i<=n;++i)
{
ITER it=S.lower_bound(c[i].first);
if(it==S.end())
{
S.erase(S.begin());
++ans;
}
else
S.erase(it);
}
printf("%d\n",ans);
ans=0;
S=tS;
for(int i=1;i<=n;++i)
{
ITER it=S.upper_bound(c[i].first);
if(it==S.end())
S.erase(S.begin());
else
{
S.erase(it);
++ans;
}
}
printf("%d\n",ans);
return 0;
}

【贪心】【multiset】 Codeforces Round #401 (Div. 2) B. Game of Credit Cards的更多相关文章

  1. 【贪心】Codeforces Round #401 (Div. 2) D. Cloud of Hashtags

    从后向前枚举字符串,然后从左向右枚举位. 如果该串的某位比之前的串的该位小,那么将之前的那串截断. 如果该串的某位比之前的串的该位大,那么之前那串可以直接保留全长度. 具体看代码. #include& ...

  2. Codeforces Round #401 (Div. 2) 离翻身就差2分钟

    Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...

  3. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  4. 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

    题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...

  5. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  6. Codeforces Round #401 (Div. 2) A B C 水 贪心 dp

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  7. Codeforces Round #401 (Div. 2) A,B,C,D,E

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  8. 【离线】【递推】【multiset】 Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet

    对询问按右端点排序,对每一列递推出包含当前行的单调不下降串最多向前延伸多少. 用multiset维护,取个最小值,看是否小于等于该询问的左端点. #include<cstdio> #inc ...

  9. Codeforces Round #401 (Div. 2) D Cloud of Hashtags —— 字符串

    题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行 ...

随机推荐

  1. ng依赖注入

    依赖注入 1.注入器在组件的构造函数中写服务constructor(private httpreq:HttpService) { } 2.提供器 providers: [HttpService],

  2. kafka.common.ConsumerRebalanceFailedException异常解决

    kafka.common.ConsumerRebalanceFailedException: group_dd-1446432618163-2746a209 can't rebalance after ...

  3. java,jenkins

    以前玩的是hudson ,现在玩的是jenkins.以前用的是Tomcat,现在不知道他们怎么不用... 1,装个Jenkins镜像. 2.配置项目: 先取个名字:exchange 配个svn: 构建 ...

  4. 使用UMeditor富文本编辑器上传图片

    注:本文系作者原创,但可随意转载. 最近写自己的网站玩儿,写到博客的部分,打算使用UMeditor,因为之前也用过(但是好像没实现图片上传的功能),感觉用起来还比较简单. 不过还是折腾了一下午...遇 ...

  5. 带依赖包的maven打包配置

    转载自:http://outofmemory.cn/code-snippet/2594/carry-yilai-bao-maven-dabao-configuration 可以在maven的packa ...

  6. 最大流算法 ISAP 模板 和 Dinic模板

    ISAP // UVa11248 Frequency Hopping:使用ISAP算法,加优化 // Rujia Liu struct Edge { int from, to, cap, flow; ...

  7. TCP(二)

    TCP半连接和全连接问题 TCP握手过程详解 如上图所示,关键部分:syns queue(半连接队列)和accept queue(全连接队列) 正常情况下的处理过程如下: 1)当server端收到cl ...

  8. HDOJ 3501 Calculation 2

    题目链接 分析: 要求的是小于$n$的和$n$不互质的数字之和...那么我们先求出和$n$互质的数字之和,然后减一减就好了... $\sum _{i=1}^{n} i[gcd(i,n)==1]=\le ...

  9. ThinkPHP 多应用多模块建立方式

    ThinkPHP3.2.2及以后版本同一应用多模块和多应用多模块的设计已经比以前的版本更加简单快捷. 注:入口文件为index.php,内容为: <?php // +-------------- ...

  10. ie8以上及非ie8情况下的写法

    <!-- [if gt ie 8]> <!--> <script src="no-ie8.js"></script>  <!- ...