Codeforces - 1166B - All the Vowels Please

140 篇文章 0 订阅
80 篇文章 0 订阅

Codeforces - 1166B - All the Vowels Please

地址

http://codeforces.com/contest/1166/problem/B

原文地址

https://www.lucien.ink/archives/431

题目

Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length k k k is vowelly if there are positive integers n n n and m m m such that n ⋅ m = k n\cdot m = k nm=k and when the word is written by using n n n rows and m m m columns (the first row is filled first, then the second and so on, with each row filled from left to right), every vowel of the English alphabet appears at least once in every row and every column.

You are given an integer k k k and you must either print a vowelly word of length k k k or print − 1 -1 1 if no such word exists.

In this problem the vowels of the English alphabet are ‘a’, ‘e’, ‘i’, ‘o’ ,’u’.

题意

问你是否存在一个长度为 k k k 的字符串,使得你将他们平铺成一个矩形之后,每行每列都包含 5 5 5 个元音字母。

题解

看是否能展开成大于等于 5 × 5 5 \times 5 5×5 的矩形,可以的话就每行循环铺一下。

代码

https://pasteme.cn/8171

#include <bits/stdc++.h>
int n, x = -1, y = -1;
char ans[int(1e5) + 7];
int index(int a, int b) {
    return a * y + b;
}
char table[] = "aeiou";
void solve(int a) {
    for (int j = 0; j < y; j++) {
        ans[index(a, j)] = table[(a + j) % 5];
    }
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (i >= 5 && n / i >= 5) {
                x = i, y = n / i;
                break;
            }
        }
    }
    if (x < 0 || y < 0) return 0 * puts("-1");
    for (int i = 0; i < x; i++) {
        solve(i);
    }
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            printf("%c", ans[index(i, j)]);
        }
    }
    putchar('\n');
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值