http://codeforces.com/contest/1141/problem/D

题目大意:

鞋子匹配,用一个小写字母表示一种颜色。L[i]表示左脚的颜色,R[i]表示右脚的颜色,只有当L[i]和R[j]的颜色差不多了,才算匹配成功。但是,有一种特殊的颜色‘?’,该颜色可以和任意另一半鞋子匹配。

思路:

取出‘?’,格外判断就好了

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n") using namespace std;
const int maxn = + ;
vector<pair<int, int> > l, r;
bool fl[maxn], fr[maxn];
char ch[maxn];
int n; int main(){
cin >> n;
scanf("%s", ch);
vector<pair<int, int> > wenhaol;
for (int i = ; ch[i] != '\0'; i++){
if (ch[i] >= 'a' && ch[i] <= 'z')
l.pb(mk(ch[i], i));
else if (ch[i] == '?')
wenhaol.pb(mk(ch[i] + , i));
}
sort(l.begin(), l.end()); scanf("%s", ch);
vector<pair<int, int> > wenhaor;
for (int i = ; ch[i] != '\0'; i++){
if (ch[i] >= 'a' && ch[i] <= 'z')
r.pb(mk(ch[i], i));
else if (ch[i] == '?')
wenhaor.pb(mk(ch[i] + , i));
}
sort(r.begin(), r.end()); vector<pair<int, int> > ans;
int lb = , rb = ;
while (lb < l.size() && rb < r.size()){
//printf("lb = %d rb = %d\n", lb, rb);
if (l[lb].fi == r[rb].fi){
ans.pb(mk(l[lb].se, r[rb].se));
fl[lb] = fr[rb] = ;
lb++, rb++;
continue;
}
/*if (l[lb].fi == '?' + 80 || r[rb].fi == '?' + 80){
ans.pb(mk(l[lb].se, r[rb].se));
fl[lb] = fr[rb] = 1;
lb++, rb++;
continue;
}*/
if (l[lb].fi > r[rb].fi && l[lb].fi != '?' + ){
rb++;
continue;
}
if (r[rb].fi > l[lb].fi && r[rb].fi != '?' + ){
lb++;
continue;
}
} lb = , rb = ;
for (int i = ; i < l.size(); i++){
if (fl[i] != && rb < wenhaor.size()){
ans.pb(mk(l[i].se, wenhaor[rb].se));
rb++; }
} for (int i = ; i < r.size(); i++){
if (fr[i] != && lb < wenhaol.size()){
ans.pb(mk(wenhaol[lb].se, r[i].se));
lb++;
}
} while (lb < wenhaol.size() && rb < wenhaor.size()){
ans.pb(mk(wenhaol[lb].se, wenhaor[rb].se));
lb++, rb++;
} printf("%d\n", ans.size());
for (int i = ; i < ans.size(); i++){
printf("%d %d\n", ans[i].fi + , ans[i].se + );
} return ;
}

Codeforces Round #547 (Div. 3) D的更多相关文章

  1. Codeforces Round #547 (Div. 3) 题解

    Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...

  2. E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题

    E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #547 (Div. 3) G 贪心

    https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...

  4. Codeforces Round #547 (Div. 3) F 贪心 + 离散化

    https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...

  5. Codeforces Round #547 (Div. 3) D. Colored Boots

    链接:https://codeforces.com/contest/1141/problem/D 题意: 给连个n长度的字符串. 求两个字符串相同字符对应位置的对数,并挨个打印. 字符:?可以代替任何 ...

  6. Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest

    链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...

  7. Codeforces Round #547 (Div. 3) A.Game 23

    链接:https://codeforces.com/contest/1141/problem/A 题意: 给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m. 不能得到时为-1. ...

  8. Codeforces Round #547 (Div. 3)

    我老人家走了四公里吃个汉堡还没吃成.垃圾肯德基.垃圾春分半价桶. 蜜雪冰城百香果加冰+烤串真是爽死了.原来二十多块钱可以吃的这么爽. A: #include <bits/stdc++.h> ...

  9. Codeforces Round #547 (Div. 3) E. Superhero Battle

    E. Superhero Battle A superhero fights with a monster. The battle consists of rounds, each of which ...

随机推荐

  1. Phabricator 在 centos 系统下发送 Email的配置

    前言 phabricator 配置email 其实很简单,配好smtp 服务器.端口.协议.用户名和登陆密码,但过程却好麻烦. 开始时跟着官网配 sendmail ,又 google 又 baidu, ...

  2. 浅谈我的UI设计之路

    时光匆匆,进入UI学习已经快两个月了,这段时间过得很充实,因为有压力才有收获. 还记的刚刚学习手绘的时候,对于这个行业只有一个初步的认识,知道自己喜欢,但是真正学习的时候才发现,我要学习的东西还有很多 ...

  3. 212. Space Replacement【LintCode by java】

    Description Write a method to replace all spaces in a string with %20. The string is given in a char ...

  4. 重磅发布丨乐维监控:全面兼容云平台,助力企业DevOps转型升级!

    2019年伊始,我们迎来了乐维监控的又一重大功能更新——云平台监控,这将有效帮助企业将云上.云下数据聚合,方便统一化的监控管理与维护!未来,乐维监控每一次的产品功能及版本更新,我们都将第一时间于此发布 ...

  5. Web挂马方式整理

    一:框架挂马 <iframe src=地址 width=0 height=0></iframe> 二:js文件挂马 首先将以下代码 document.write("& ...

  6. LINUX内核分析第二周学习总结——操作系统是如何工作的

    LINUX内核分析第二周学习总结——操作系统是如何工作的 张忻(原创作品转载请注明出处) <Linux内核分析>MOOC课程http://mooc.study.163.com/course ...

  7. java入门--4110:圣诞老人的礼物-Santa Clau’s Gifts

    学习了一下java的语法,就用poj上的题目做作练习,好更快的熟悉常用的java语法. 题目在这里 http://bailian.openjudge.cn/practice/4110/ import ...

  8. 第二个spring冲刺第5天

    针对与昨天的讨论内容,今天进行了开会研讨给意见. 在今天中有了点进展,各方面都有改善,离程序的完成度又前进了一大步.

  9. 作业六:小学生四则运算之NABCD模型与产品Backlog。

    NABCD模型与产品Backlog NABCD模型 ) N (Need 需求) 方便了老师和学生,使他们可以想要的时候随时可以得到,省时省力,快速出题,马上得到答案. ) A (Approach 做法 ...

  10. Kafka数据可靠性深度解读

    原文链接:http://www.infoq.com/cn/articles/depth-interpretation-of-kafka-data-reliability Kafka起初是由Linked ...