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. stl源码剖析 详细学习笔记 仿函数

    //---------------------------15/04/01---------------------------- //仿函数是为了算法而诞生的,可以作为算法的一个参数,来自定义各种操 ...

  2. 软件测试_测试工具_Loadrunner_IP欺骗

    一.设置IP欺骗的原因: 1.当某个IP的访问过于频繁或者访问量过大时,服务器会拒绝访问请求: 2.某些服务器配置了负载均衡,使用同一个IP不能测出系统的实际性能.Loadrunner中的IP欺骗通过 ...

  3. sqli-labs 下载、安装

    sqli-labs 下载.安装 下载地址:https://github.com/Audi-1/sqli-labs phpstudy:http://down.php.cn/PhpStudy2018021 ...

  4. mac osx 初次使用PHP环境搭建

    非常简单,一共2个步骤: Step1: 启动Apache mac osx 系统默认安装Apache服务. 首先打开terminal,输入: sudo apachectl start 如果需要输入密码, ...

  5. ajax设置自定义请求头

    1, $.ajax({ url:apiUrl, type:"get", timeout : 5000, //超时时间设置,单位毫秒 dataType: "json&quo ...

  6. 《Linux内核分析》第一周学习小结 计算机是如何工作的?

    <Linux内核分析>第一周.计算机是如何工作的? 20135204 郝智宇  一.存储程序计算机工作模型 1.      冯诺依曼体系结构: 数字计算机的数制采用二进制:计算机应该按照程 ...

  7. 20135220谈愈敏Blog1_计算机是如何工作的

    计算机是如何工作的 存储程序计算机工作模型 冯诺依曼体系结构 从硬件角度来看:CPU和内存,由总线连接,CPU中有一个名为IP的寄存器,总是指向内存的某一块:CS,代码段,执行命令时就取IP指向的一条 ...

  8. git的使用与学习

    1.将本地项目推送到Github $ git remote add origin 仓库地址 // 关联远程仓库 $ git push origin master // 推送到远程仓库 如果远程仓库有本 ...

  9. ElasticSearch 2 (33) - 信息聚合系列之聚合过滤

    ElasticSearch 2 (33) - 信息聚合系列之聚合过滤 摘要 聚合范围限定还有一个自然的扩展就是过滤.因为聚合是在查询结果范围内操作的,任何可以适用于查询的过滤器也可以应用在聚合上. 版 ...

  10. Team抢救最后一下

    Team抢救最后一下 Task1:Team抢救的总结 秦玉:       非常荣幸能以团队的方式获得这次的小黄衫,这件衣服的意义不仅是这门课的奖励,也会是我们整个抢救团队的一个见证和回忆~       ...