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

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

用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. POJ2516:Minimum Cost(最小费用最大流)

    Minimum Cost Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19088   Accepted: 6740 题目链 ...

  2. 单个回调函数中返回多个Request以及Item

    import scrapy from myproject.items import MyItem class MySpider(scrapy.Spider): name = 'example.com' ...

  3. AngularJs学习——何时应该使用Directive、Controller、Service?

    翻译:大漠穷秋 原文链接:http://kirkbushell.me/when-to-use-directives-controllers-or-services-in-angular/ 一.简述 A ...

  4. Python学习笔记 - day5 - 文件操作

    Python文件操作 读写文件是最常见的IO操作,在磁盘上读写文件的功能都是由操作系统提供的,操作系统不允许普通的程序直接操作磁盘(大部分程序都需要间接的通过操作系统来完成对硬件的操作),所以,读写文 ...

  5. 常见的makefile写法【转】

    转自:http://blog.csdn.net/ghostyu/article/details/7755177 版权声明:本文为博主原创文章,未经博主允许不得转载. .目标名称,摆脱手动设置目标名称 ...

  6. Yeelight介绍

    1. 介绍 Yeelight是小米生态链中的WiFi智能灯泡,本文介绍它的接入和控制实现: Yeelight使用的是自定义的私有协议,该协议采用了类似SSDP的发现机制和基于JSON的控制命令 2. ...

  7. Linux虚拟地址空间布局以及进程栈和线程栈总结【转】

    转自:http://www.cnblogs.com/xzzzh/p/6596982.html 原文链接:http://blog.csdn.net/freeelinux/article/details/ ...

  8. 使用go写一个检测tcpudp状态的包

    使用go写一个检测tcpudp状态的包 http://www.2cto.com/os/201501/367596.html

  9. 全面理解面向对象的 JavaScript(转载)

    http://www.ibm.com/developerworks/cn/web/1304_zengyz_jsoo/#resources 前言 当今 JavaScript 大行其道,各种应用对其依赖日 ...

  10. Java常见知识点(一)

    1.+不仅可作为加法运算符使用,还可作为字符串连接运算符使用.   2.a = b = c = 7;//虽然java支持这种一次为多个变量赋值的写法,但这种写法导致程序的可读性降低,因此不推荐这样写. ...