CodeForces - 1141D Colored Boots(暴力+水题)
题目链接:点击查看
题目大意:给出两个字符串s和t,两个字符串中相同的字母可以匹配,问号可以和任意字符匹配,现在问两个字符串最多能匹配多少个字符,并给出匹配的下标
题目分析:挺好玩的一道水题,大体思路就是先遍历一遍两个字符串,将所有的字符下标都分类储存起来,按照以下顺序匹配:
- s串和t串中的普通字母
- s串的问号和t串中的普通字母
- t串的问号和s串中的普通字母
- s串的问号和t串中的问号
按照上面的顺序暴力就可以了
代码:
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=2e5+100;int main()
{
// freopen("input.txt","r",stdin);
// ios::sync_with_stdio(false);int n;string a,b;cin>>n>>a>>b;vector<int>aa[27];//0~25储存字母,26储存问号vector<int>bb[27];vector<pair<int,int>>ans;for(int i=0;i<a.size();i++){if(a[i]=='?')aa[26].push_back(i+1);elseaa[a[i]-'a'].push_back(i+1);}for(int i=0;i<b.size();i++){if(b[i]=='?')bb[26].push_back(i+1);elsebb[b[i]-'a'].push_back(i+1);}for(int i=0;i<26;i++)//优先匹配字母{while(aa[i].size()&&bb[i].size()){ans.push_back(make_pair(aa[i].back(),bb[i].back()));aa[i].pop_back();bb[i].pop_back();}}if(aa[26].size())//匹配a中的问号{for(int i=0;i<26;i++){while(aa[26].size()&&bb[i].size()){ans.push_back(make_pair(aa[26].back(),bb[i].back()));aa[26].pop_back();bb[i].pop_back();} }}if(bb[26].size())//匹配b中的问号{for(int i=0;i<26;i++){while(bb[26].size()&&aa[i].size()){ans.push_back(make_pair(aa[i].back(),bb[26].back()));aa[i].pop_back();bb[26].pop_back();} }}while(aa[26].size()&&bb[26].size())//匹配两个串中的问号{ans.push_back(make_pair(aa[26].back(),bb[26].back()));aa[26].pop_back();bb[26].pop_back();}cout<<ans.size()<<endl;for(int i=0;i<ans.size();i++)printf("%d %d\n",ans[i].first,ans[i].second);return 0;
}
CodeForces - 1141D Colored Boots(暴力+水题)相关推荐
- Codeforces 864 A Fair Game 水题
题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...
- 【CodeForces - 569B】Inventory (水题)
题干: Companies always have a lot of equipment, furniture and other things. All of them should be trac ...
- codeforces 702A A. Maximum Increase(水题)
题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...
- CodeForces - 1287B Hyperset(暴力水题)
题目链接:点击查看 题目大意:给出"集合"的定义: 集合中必须有三个元素 每个元素的每个特征值必须全部相同或者全部不同,不能存在两者相同但与第三者不同 现在给出n个元素以及m个特征 ...
- Codeforces gym 100685 C. Cinderella 水题
C. Cinderella Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/ ...
- codeforces 667A A. Pouring Rain(水题)
题目链接: A. Pouring Rain time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 【CodeForces - 485A】Factory (水题,抽屉原理,tricks)
题干: One industrial factory is reforming working plan. The director suggested to set a mythical detai ...
- CodeForces - 25A IQ test【水题】
题目链接:https://codeforces.com/contest/25/problem/A #include <iostream> using namespace std; int ...
- CodeForces - 29A Spit Problem【水题】
题目链接:https://codeforces.com/contest/29/problem/A #include <iostream> #include <cstdio> # ...
最新文章
- C语言 找数码是否存在
- gradle编译出错:Execution failed for task #39;:app:compileTestDebugJava#39;.
- 北斗导航 | Modified Tropospheric:对流层延迟计算(matlab代码)
- 图像数据格式基础知识
- sdut 区间覆盖问题
- mysql被除数为0不报错_MySQL:关系除法
- (71)FPGA时钟双沿约束如何做?
- 50. Pow(x, n) (MATH)
- 大数据是普惠金融的未来!
- Vue 3 + Vite + Eslint + prettier + husky + lint-staged 搭建基础项目
- 我的linux系统怎么输入pv,如何在Linux系统中使用pv命令
- 怎么做手游性能测试?
- 矩阵变换器MATLAB仿真,其他仿真模型也可 图中为三相矩阵 变换器仿真模型及其输入输出电流波形
- Linux磁盘热插拔命令
- 嵌入式软件开发学习 工程师要掌握的基本技能
- P2P网络认识与实践
- 基于FPGA的任意信号发生器
- 做城市规划设计,如何下载地形图?
- Proxy与Object.defineProperty的优劣对比
- 【最新版】一款容易吸粉的盲盒抽奖小程序源码