Codeforces-1844-D. Row Major

8 篇文章 0 订阅
2 篇文章 0 订阅

题目链接: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;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AbsoluteClownMaster

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值