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

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

用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. Codeforces Round #520 (Div. 2) C. Banh-mi

    C. Banh-mi time limit per test:1 second memory limit per test:256 megabytes 题目链接:https://codeforc.es ...

  2. 安卓下拉刷新空间SwipeRefreshLayout的基本使用

    1.先写布局文件 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/refresh" androi ...

  3. ERROR: Found lingering reference file hdfs

    Found lingering reference异常 ERROR: Found lingering reference file hdfs://jiujiang1:9000/hbase/month_ ...

  4. 对比append插入数据产生的redo量

    --版本信息 SELECT * FROM v$version; Oracle - Prod PL - Production CORE Production TNS - Production NLSRT ...

  5. Intelij idea新窗口打开项目设置

    1.idea 打开后 file->setting   2.appearance&behave->system setting->open project in new win ...

  6. bzoj 5010: [Fjoi2017]矩阵填数

    Description 给定一个 h*w 的矩阵,矩阵的行编号从上到下依次为 1..h,列编号从左到右依次1..w.在这个矩阵中你需要在每 个格子中填入 1..m 中的某个数.给这个矩阵填数的时候有一 ...

  7. Django-views,用户认证,login_requierd()

    分别是认证,登入,注销的功能 authenticated():验证是否登录 user = authenticate(username='someone',password='somepassword' ...

  8. MySQL 查询语句练习2

    创建表 /* Navicat MySQL Data Transfer Source Server : localhost_3306 Source Server Version : 50719 Sour ...

  9. objc_msgSend arm64 崩溃问题

    http://blog.csdn.net/chenyong05314/article/details/42121001 2014-12-24 10:49 878人阅读 评论(0) 收藏 举报 转载自: ...

  10. VMX指令集

    指令 作用 VMPTRLD 加载一个VMCS结构体指针作为当前操作对象 VMPTRST 保存当前VMCS结构体指针 VMCLEAR 清除当前VMCS结构体 VMREAD 读VMCS结构体指定域 VMW ...