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 ...
随机推荐
- 微信小程序实现各种特效实例
写在前面 最近在负责一个微信小程序的前端以及前后端接口的对接的项目,整体上所有页面的布局我都已经搭建完成,里面有一些常用的特效,总结一下,希望对大家和我都能有所帮助 实例1:滚动tab选项卡 先看一下 ...
- .Net Core 分布式微服务框架 - Jimu 添加 Swagger 支持
系列文章 .Net Core 分布式微服务框架介绍 - Jimu .Net Core 分布式微服务框架 - Jimu 添加 Swagger 支持 一.前言 最近有空就优化 Jimu (一个基于.Net ...
- Asp.Net_Get跟Post
1. Get(即使用QueryString显式传递) 方式:在url后面跟参数. 特点:简单.方便. 缺点:字符串长度最长为255个字符:数据泄漏在url中. 适用数据 ...
- 【Tableau】电商广告投放的地域分析
分析师的职责是利用处理数据获取信息,提炼规律,帮助企业正确决策业务方向. 所以,一个好的分析师绝不能被数据所困,既要深入业务,理解业务,也要高瞻远瞩,以领导者的思维借助数据分析的辅助做出判断. [结构 ...
- idea使用actiBPM插件中文乱码
idea 安转activiti插件后,编辑流程图发现保存后中文乱码,并且idea的字符集(Settings—>Editor—>File Encodings)已经设置为UTF-8,流程图中中 ...
- Python3.7 + jupyter安装(CentOS6.5)
Python3.7 + jupyter安装(CentOS6.5) 方法一(anaconda): anaconda是一个开源的Python发行版本 包含conda,python等大量的科学包以及依赖 优 ...
- A1043 Is It a Binary Search Tree (25 分)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- LINUX内核分析第六周学习总结——进程的描述和进程的创建
LINUX内核分析第六周学习总结——进程的描述和进程的创建 张忻(原创作品转载请注明出处) <Linux内核分析>MOOC课程http://mooc.study.163.com/cours ...
- time since epoch
C++11 提供了新的获取系统时间的库函数,在获取时间的时候一般常用的是获取time since epoch,下面来看一下如何获取这个时间. #include <iostream> #in ...
- beta yz 5
031602111 傅海涛 1.今天进展 接口微调修正 2.存在问题 文档转化太久 3.明天安排 完成全部接口的交互 4.心得体会 文档转化需要好好优化 031602115 黄家雄 1.界面优化 2. ...