Codeforces Round #566 (Div. 2)C(字符串,SET)
#include<bits/stdc++.h>
using namespace std;
string s[100007];
set<int>st[100007][7];
int t[207];
int a[100007],b[100007][2],c[100007],d[100007][2];
int main(){
t['a']=1;
t['e']=2;
t['i']=3;
t['o']=4;
t['u']=5;
int n;
cin>>n;
for(int i=1;i<=n;++i){
cin>>s[i];
int cnt=0;
char last;
for(int j=0;j<s[i].length();++j){
if(s[i][j]=='a'||s[i][j]=='e'||s[i][j]=='i'||s[i][j]=='o'||s[i][j]=='u'){
cnt++;
last=s[i][j];
}
}
if(cnt){
st[cnt][t[last]].insert(i);
}
}
int cnt1=0,cnt2=0;
int num1=0,num2=0;
for(int i=1;i<=100000;++i){
num1=0;
for(int j=1;j<=5;++j){
num2=0;
for(auto it:st[i][j]){
a[++num2]=it;//将有i个元音字母并且结尾元音字母编号为j的字符串序号放进a数组中
}
for(int k=1;k<num2;k+=2){//将a数组中的字符串成双取出到b数组,他们都拥有相同的元音字母个数和最后一个字母
b[++cnt1][0]=a[k];
b[cnt1][1]=a[k+1];
}
if(num2&1)//a数组有一个余下的字符串序号
c[++num1]=a[num2];//c数组放成单的字符串序号,他们都拥有相同的元音字母个数i,却没有相同的结尾元音字母
}
for(int j=1;j<num1;j+=2){//将c数组中的字符串成双取出到d数组,他们都拥有相同的元音字母个数,结尾元音字母不同使得它们只能放在每行的第一个
d[++cnt2][0]=c[j];
d[cnt2][1]=c[j+1];
}
}
if(cnt1<=cnt2){//拥有相同元音字母个数的对数少于不同的
cout<<cnt1<<"\n";
for(int i=1;i<=cnt1;++i){
cout<<s[d[i][0]]<<" "<<s[b[i][0]]<<"\n";
cout<<s[d[i][1]]<<" "<<s[b[i][1]]<<"\n";
}
}
else{
int ans=cnt2+(cnt1-cnt2)/2;//拥有相同元音字母个数的对数较多,优先让它们和不同的进行搭配,再两两自成对
cout<<ans<<"\n";
for(int i=1;i<=cnt2;++i){
cout<<s[d[i][0]]<<" "<<s[b[i][0]]<<"\n";
cout<<s[d[i][1]]<<" "<<s[b[i][1]]<<"\n";
}
for(int i=cnt2+1;i<cnt1;i+=2){
cout<<s[b[i][0]]<<" "<<s[b[i+1][0]]<<"\n";
cout<<s[b[i][1]]<<" "<<s[b[i+1][1]]<<"\n";
}
}
return 0;
}
Codeforces Round #566 (Div. 2)C(字符串,SET)的更多相关文章
- Codeforces Round #566 (Div. 2)
Codeforces Round #566 (Div. 2) A Filling Shapes 给定一个 \(3\times n\) 的网格,问使用 这样的占三个格子图形填充满整个网格的方案数 如果 ...
- Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- Codeforces Round #329 (Div. 2)A 字符串处理
A. 2Char time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #566 (Div. 2) C. Beautiful Lyrics
链接: https://codeforces.com/contest/1182/problem/C 题意: You are given n words, each of which consists ...
- Codeforces Round #566 (Div. 2) B. Plus from Picture
链接: https://codeforces.com/contest/1182/problem/B 题意: You have a given picture with size w×h. Determ ...
- Codeforces Round #566 (Div. 2) A. Filling Shapes
链接: https://codeforces.com/contest/1182/problem/A 题意: You have a given integer n. Find the number of ...
- Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)
传送门 题目 \[ \begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{aligned} \] 思路 我们通过迭代发 ...
- Codeforces Round #566 (Div. 2)题解
时间\(9.05\)好评 A Filling Shapes 宽度为\(3\),不能横向填 考虑纵向填,长度为\(2\)为一块,填法有两种 如果长度为奇数则显然无解,否则\(2^{n/2}\) B Pl ...
随机推荐
- 爬虫入门 beautifulsoup库(一)
先贴一个beautifulsoup的官方文档,https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#id12 requ ...
- C#中如何将字符串或者字符串数组写入文本文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- python做批量剪切、旋转等小程序
我自己在学习python时自己动手做了几个简单实用的小程序,对大家做图像的增强很有效果,我包括我的同学目前都在用我的小程序来做图像增强,非常的实用.话不多说上代码: import globimport ...
- AcWing 853. 有边数限制的最短路 bellman-ford 结构体
//存在负权值 处理负环 //如果能求出来 一般是不存在负权回路 //如果有负回路 那最小距离可能是负无穷 #include <cstring> #include <iostream ...
- vue中子组件调用父组件里面的数据和方法 父组件调用子组件的数据和方法
1.子组件直接调用父组件的数据和方法 在父组件father,vue <template> <div> <!-- 父组件里面的数据 --> <p>父组件里 ...
- vue+vuex项目中怎么实现input模糊查询
1,首先给input框添加方法,但是用的是element-ui的组件,对input进行了封装,不能直接用原生的方法!,在element组件中,input框中方法有实例参数$event,代表事件对象 ...
- VS2015生成代码图
熟悉代码调用流程,可以在调试结束前显示代码图,操作位置: 比如开源的caffe_ocr的代码图:
- svn还原与本地版本回退
今天遇到了一个情况,由于没及时更新,对整个项目进行了Ctrl+shift+O,提交代码时冲突:然后就先还原项目,导致之前没有冲突的代码也回退了.然后就在eclipse中获取本地的版本记录,并回退 具体 ...
- Nexus坑人系列-interface Unknown state L3 Not Ready
这个情况也容易出现在新使用设备的时候,当设备上没有L3接口模块的时候,这个问题就出现了. 接下来,尤其是如果我们需要运行VPC(并且如果正在运行N5K,N7K等!),则需要在交换机上配置第3层接口. ...
- Ubuntu中获取和使用uiautomatorviewer
图省事的办法是直接在网上找个android platform tools的某个版本下载下来 比如这个网站里面的:Android SDK工具——Platform-tools 个人比较倾向于先下载andr ...