Codeforces1335 E2. Three Blocks Palindrome (hard version) 详细代码

博客主要探讨了Codeforces 1335比赛中的E2难题——Three Blocks Palindrome (hard version),如何构建特殊的回文字符串。题目要求由三部分组成回文串:相同字符的x个重复、y个重复,再加x个重复。文章通过举例和代码注释解释了解题思路,涉及字符串处理和回文串构建技巧。
摘要由CSDN通过智能技术生成

手速场~

A. Candies and Two Sisters

第一个人必须大于第二个,求方法数

#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1e5+5;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        if(n%2==1)
            printf("%d\n",n/2);
        else
            printf("%d\n",n/2-1);
    }
}

 

B. Construct the String

   n a b

每个样例要输出 n 个字符,每个长度为 a 的字符串中要有 b 个不同的字符

注:考虑特殊情况  6 1 1  ——>  abcdef

#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=1e5+5;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,a,b;
        scanf("%d%d%d",&n,&a,&b);
        string s="",ans="";
        if(a==1&&b==1)
        {
            int k=0;
            s="abcdefghijklmnopqrstuvwxyz";
            for(int i=0; i<n; i++)
            {
                if(k==26)
                    k=0;
        
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值