题目链接:Problem - D - Codeforces
题目大意:
求最长周期字符串
解题思路:
因为每个格子相邻的字符不能重复且从左向右,从上到下读字符串,所以不难发现如果每一行所放的字符串都为同一个字符串的话一定不符合题目要求,所以每当字符串的长度刚刚好够其所占的行数就要给这个字符串的长度加一(贪心),这里我们可以默认所有的字符串都是“abcdefghijklmnopqrstuvwxyz”的子字符串每当长度加一就找个值记录一下就好,答案就是将长度内的字符串循环输出至题目所给定的长度n
代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define N 1000010
#define M 998244353
#define inf 0+3f3f3f3f
#define INF 0+3f3f3f3f3f3f3f3f
using namespace std;
typedef pair<int, int> PII;
typedef pair<int, bool> PIB;
typedef pair<PII, int> PIII;
typedef pair<PII, PII> PIIPII;
typedef pair<int, vector<int> > PIV;//若俩尖括号一起则中间必须加空格
typedef long long ll;
typedef unsigned long long ull;
int t, n;
int main() {
cin >> t;
while (t--) {
cin >> n;
int num = 2;
for (int i = 2; i < n; i++) {
if (n % i == 0) {
if (num / i == 1 && num % i == 0)num++;
}
}
int pos = 0;
while (pos < n)
for (char i = 'a'; i < 'a' + num; i++) {
cout << i;
pos++;
if (pos == n)break;
}
cout << endl;
}
return 0;
}