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 ...
随机推荐
- window10 上的mysql8.0.13的数据库服务丢失后,找回方法
1.由于mysql8 的 话是默认有一个配置文件的,所以在执行 初始化mysql8 mysqld --initialize #执行这个的原因是:因为之前使用的是Mysql8中自带的那个默认的配置文件 ...
- win api + 基础乐理产生正弦波声音
暂时记录. 感觉想写个电子钢琴乐程序了,不过感觉音有点怪怪的. #include <iostream> #include <windows.h> #include <Mm ...
- 使用spring中遇到"java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor"问题
项目中缺少aopalliance的jar包,下载一个相应的jar加入项目中就可以解决问题. 下载链接:http://www.java2s.com/Code/Jar/a/Downloadaopallia ...
- 一个实例 ---灵活使用jquery选择器实现input一个key,多个value 。 用ajax传递对象到后台控制器
标题可能不是很清晰,我们看实例: 简单来说就是需要实现sku的功能...一件商品可以有多个属性, 一个属性可以有多个值 . 最后以json格式存到数据库 难点一: 如何实现input输入框的弹性使用 ...
- AcWing 837. 连通块中点的数量
#include <iostream> using namespace std; ; int n, m; int p[N], size[N]; int find(int x) { if ( ...
- BFSDFS模板
BFS模板: private static void bfs(HashMap<Character, LinkedList<Character>> graph,HashMap&l ...
- html2canvas.js 图片不显示
html2canvas.js 图片不显示 在服务器端打开 就可以, 但是在本地就不显示图片. 查找百度,是因为图片不能跨域. 在给非编程人员使用的时候,建议把所有的图片,转化为base64,就可以直接 ...
- 本地mongodb数据库导出到远程数据库中
把本地Mongodb中的数据导入(批量插入)到服务器的数据库中 1.导出数据: mongoexport -d admin -c users -o outdatafile.dat 选项解释: -d 指明 ...
- jango 模型管理数据model,数据库外键主键与一对一,一对多,多对多关系
四.models.py 定义和管理模型: 4.1模型class的属性就映射与数据库的字段参数 继承models.Model class TestClass(models.Model): 4.2在数据库 ...
- 分段函数&数学函数
本题要求计算下列分段函数f(x)的值(x为从键盘输入的一个任意实数): 输入格式: 直接输入一个实数x 输出格式: 在一行中按“f(x)=result”的格式输出,其中x与result都保留三位小数. ...