Codeforces Round #561 (Div. 2) B. All the Vowels Please

链接:https://codeforces.com/contest/1166/problem/B

题意:

Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length kk is vowelly if there are positive integers nn and mm such that nm=kn⋅m=k and when the word is written by using nn rows and mm 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 kk and you must either print a vowelly word of length kk or print 1−1 if no such word exists.

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

 思路:

先求出k的所有因子,如果能找到两个大于等于5的因子,就挨个往矩阵里填因子,

否则就-1.

代码:

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

char s[5] = {'a', 'e', 'i', 'o', 'u'};

int main()
{
    int n;
    cin >> n;
    set<int> yinzi;
    for (int i = 1;i*i <= n;i++)
        if (n%i == 0)
            yinzi.insert(i), yinzi.insert(n/i);
    for (auto it = yinzi.begin();it != yinzi.end();++it)
    {
        if ((*it) >= 5 && n/(*it) >= 5)
        {
            for (int i = 0;i < (*it);i++)
            {
                int pos = i;
                for (int j = 1;j <= n/(*it);j++)
                    cout << s[(pos++)%5];
            }
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

  

转载于:https://www.cnblogs.com/YDDDD/p/10900121.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值