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 ...
随机推荐
- centos7 部署mysql-5.7.20
一.系统环境 系统:CentOS Linux release 7.5 mysqlb进制包:mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz 1)依赖包安装 yum ...
- CoreDNS Plugins ---> hosts
需求 kubernetes集群外部有少量服务,kubernetes集群内部pod需要通过服务所在的主机的hostname访问服务. 解决方案 通过coredns的hosts插件配置kubernetes ...
- Google C++ 编码规范
刚刚看到一位博主的文章分享Google C++ 编码规范 本人做一下记录,方便以后学习.. 中文在线版本地址: http://zh-google-styleguide.readthedocs.io/e ...
- 微软职位内部推荐-SW Engineer II for Embedded System
微软近期Open的职位: Do you have a passion for embedded devices and services?   Does the following m ...
- JS高级程序设计学习笔记1
javascript产生的原因: 在拨号上网时代,表单数据必须发送到服务器端才能验证输入值得有效性,JavaScript的研发就是为了解决这个问题,以便在客户端就验证输入值的有效性. ECMAScri ...
- HDU Ignatius's puzzle
链接 [http://acm.hdu.edu.cn/showproblem.php?pid=1098] 分析: 数学归纳法 f(1) = 18 + ka; 假设f(x) = 5x^13+13x^5+k ...
- c# 简易绘制C语言头文件包含关系图
最近在做一个项目的移植工作,项目很大,光c文件大约有1800多.由于某些需要,想要对某些代码文件引用的.h文件进行分析. 网上找了好久,暂无发现类似的工具. 正好,今天放假,就做了这么个工具. 好了, ...
- Python Pandas read_csv报错
为实现文本去重(将前面采集的数据进行两两对比删除重复),写了以下代码. #-*- coding: utf-8 -*-import pandas as pd inputfile = 'e:/data/H ...
- python 图像处理(从安装Pillow开始)
python2.x及以下用的是PIL(图像处理库是 PIL(Python Image Library)),最新版本是 1.1.7 可在http://www.pythonware.com/produc ...
- 20172319 《Java程序设计教程》第7周学习总结
20172319 2018.04.11-16 <Java程序设计教程>第7周学习总结 目录 教材学习内容总结 教材学习中的问题和解决过程 代码调试中的问题和解决过程 代码托管 上周考试错题 ...