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 ...
随机推荐
- JS高级---原型和原型链
原型和原型链 原型链是一种关系, 实例对象和原型对象之间的关系,关系是通过实例对象中浏览器使用的原型(__proto__)来联系的 自定义构造函数,通过实例化,创建实例对象 实例对象中__proto_ ...
- java 子线程异常处理
如何在父线程中捕获来自子线程的异常呢 方法一:子线程中try... catch... 方法二:为线程设置异常处理器UncaughtExceptionHandler (异常处理也是在子线程中执行,相当于 ...
- JVM的方法区和永久带是什么关系?
什么是方法区? 方法区(Method Area)是jvm规范里面的运行时数据区的一个组成部分,jvm规范中的运行时数据区还包含了:pc寄存器.虚拟机栈.堆.方法区.运行时常量池.本地方法栈. 方法区存 ...
- 【安卓逆向】反编译ELF的另类技巧
IDA 反编译 ObjDump反编译 ObjDump是ndk环境自带的一个脚本,在android-ndk-r10c/toolchains/arm-linux-androideabi-4.9/prebu ...
- 【原】shell增加定时任务
通过shell脚本增加定时任务:#CRON_FILE="/var/spool/cron/root" (centos系统) CRON_FILE="/var/spool/cr ...
- nginx配置 yii2 URL重写规则 SSI配置使shtml
location / { // 加上红色部分 重写url try_files $uri $uri/ /index.php?$args; if (!-e $request_filename){ rewr ...
- SSHException: Error reading SSH protocol banner
当我在使用ssh 远程connect 另一台机器的server 时出现了错误,错误如下,起初以为是自己代码写的有问题,后来本地了一下看了跑的没问题,我就开始根据报错去查寻原因, 起初在论坛博客看到这 ...
- eclipse 鼠标悬停提示
如果想要关闭鼠标悬停提示,只要把Window --> Preferences... --> Java --> Editor --> Hovers 把 Combined Hove ...
- JS高级---工厂模式创建对象和自定义构造函数创建对象的区别
创建对象:工厂模式和自定义构造函数的区别 共同点: 都是函数, 都可以创建对象, 都可以传入参数 区别: 工厂模式: 函数名是小写 有new, 有返回值 new之后的对象是当前的对象 直接调用 ...
- 洛谷 P1843 奶牛晒衣服(二分答案)
嗯... 题目链接:https://www.luogu.com.cn/problem/P1843 我们二分枚举时间,看看那些衣服在蒸发后还要用烘干机,则用cnt记录它的时间. 注意w数组在操作中不能变 ...