Codeforces Round #547 (Div. 3) D
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的更多相关文章
- Codeforces Round #547 (Div. 3) 题解
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...
- 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 ...
- Codeforces Round #547 (Div. 3) G 贪心
https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...
- Codeforces Round #547 (Div. 3) F 贪心 + 离散化
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...
- Codeforces Round #547 (Div. 3) D. Colored Boots
链接:https://codeforces.com/contest/1141/problem/D 题意: 给连个n长度的字符串. 求两个字符串相同字符对应位置的对数,并挨个打印. 字符:?可以代替任何 ...
- Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest
链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...
- Codeforces Round #547 (Div. 3) A.Game 23
链接:https://codeforces.com/contest/1141/problem/A 题意: 给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m. 不能得到时为-1. ...
- Codeforces Round #547 (Div. 3)
我老人家走了四公里吃个汉堡还没吃成.垃圾肯德基.垃圾春分半价桶. 蜜雪冰城百香果加冰+烤串真是爽死了.原来二十多块钱可以吃的这么爽. A: #include <bits/stdc++.h> ...
- 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 ...
随机推荐
- 设计模式 笔记 中介者模式 Mediator
//---------------------------15/04/27---------------------------- //Mediator 中介者模式----对象行为型模式 /* 1:意 ...
- 浅谈 iOS 中的 Activity Indicator
Activity Indicator 是iOS开发中必不可少的一个视图.本文就简单地总结一下这个Activity Indicator 的使用方法. 默认 Activity Indicator 以下的函 ...
- Linux shell (6)
1.linux shell函数: 将一组命令集或语句形成一个可用的块,这些语句块成为函数. 2.shell 函数的组成: 函数名:函数的名字,注意一个脚本中函数名要唯一,否则会引起调用函数紊乱 函 ...
- DFA化简
首先是未化简DFA的转换表 NFA状态 DFA状态 a b {0,1,2,4,7} A B C {1,2,3,4,6,7,8} B B D {1,2,4,5,6,7} C B C {1,2,4,5,6 ...
- 面向 Kubernetes 编程: Kubernetes 是下一代操作系统
转自:https://github.com/answer1991/articles/blob/master/Kubernetes-is-the-next-generation-os.md 摘要 此文章 ...
- VMware10 安装centos6.7 设置NAT模式固定ip
https://www.cnblogs.com/yychnbt/p/5173761.html
- Actual Time Cost
- Linux读书笔记第一周
1.Unix内核的特点:简洁:抽象:可移植性:进程创建:清晰的层次化结构. Linux内核是一种自由/开源的软件,设计思想与Unix系统相似(一切皆文件,特定的单一用途 & 简单的组合方式) ...
- 炸弹人的Alpha版使用说明
本游戏是一款手机游戏,学生可以在无聊时打发时间,放松心情.现在只有三关,但游戏运行还算可以. 注意事项: 目前游戏还有一些不好的地方,游戏无法暂停,如果游戏任务死亡,则无法重开. 游戏后面的关卡还需要 ...
- 解决SVN安装语言包后无法选择中文的问题(亲测可行)
TortoiseSVN_1.8.8安装后无法选择简体中文,或者安装语言包后也无法选择中文 1.找到 SVN 安装目录,把里面的Languages文件夹删掉 2.安装语言包,百度一下也有很多安装包和语言 ...