String

本文介绍了一种算法,用于将一个由0和1组成的字符串拆分成多个子串,确保每个子串都是其所有循环旋转中字典序最小的。通过从后往前枚举并检查每个可能的子串,可以找到所有符合条件的完美子串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:https://ac.nowcoder.com/acm/contest/887/A

链接:https://ac.nowcoder.com/acm/contest/887/A
来源:牛客网

题目描述

A string is perfect if it has the smallest lexicographical ordering among its cyclic rotations.
For example: "0101" is perfect as it is the smallest string among ("0101", "1010", "0101", "1010").

Given a 01 string, you need to split it into the least parts and all parts are perfect.

输入描述:

The first line of the input gives the number of test cases, T (T≤300)T\ (T \leq 300)T (T300). test cases follow.

For each test case, the only line contains one non-empty 01 string. The length of string is not exceed 200.

输出描述:

For each test case, output one string separated by a space.
示例1

输入

复制
4
0
0001
0010
111011110

输出

复制
0
0001
001 0
111 01111 0
题目大意:把一个串拆分成几个串,保证拆分后的串都是字典序最小的串
思路:从后往前暴力枚举串,如果串是一个字典序最小的串,那么改变起点,一直枚举下去,就是答案了
看代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int Get_min(string s)//得到串的最小表示所在的下标
{
    int n=s.size();int i=0,j=1,k=0;
    while(i<n&&j<n&&k<n)
    {
        int t=s[(i+k)%n]-s[(j+k)%n];
        if(!t) k++;
        else
        {
            if(t<0) j+=k+1;
            else i+=k+1;
            if(i==j) j++;
            k=0;
        }
    }
    int pos=min(i,j);
    return pos==0;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        string s;cin>>s;
        int len=s.size();
        int l=0,r=len;
        while(true)
        {
            for(int i=r;i>=0;i--)//枚举终点
            {
                string t=s.substr(l,i-l);
                if(Get_min(t))
                {
                    for(int j=l;j<i;j++) cout<<s[j];cout<<" ";
                    l=i;break;
                }
            }
            if(l==r) break;
        }
        cout<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/caijiaming/p/11327330.html

"sgmediation.zip" 是一个包含 UCLA(加利福尼亚大学洛杉矶分校)开发的 sgmediation 插件的压缩包。该插件专为统计分析软件 Stata 设计,用于进行中介效应分析。在社会科学、心理学、市场营销等领域,中介效应分析是一种关键的统计方法,它帮助研究人员探究变量之间的因果关系,尤其是中间变量如何影响因变量与自变量之间的关系。Stata 是一款广泛使用的统计分析软件,具备众多命令和用户编写的程序来拓展其功能,sgmediation 插件便是其中之一。它能让用户在 Stata 中轻松开展中介效应分析,无需编写复杂代码。 下载并解压 "sgmediation.zip" 后,需将解压得到的 "sgmediation" 文件移至 Stata 的 ado 目录结构中。ado(ado 目录并非“adolescent data organization”缩写,而是 Stata 的自定义命令存放目录)目录是 Stata 存放自定义命令的地方,应将文件放置于 "ado\base\s" 子目录下。这样,Stata 启动时会自动加载该目录下的所有 ado 文件,使 "sgmediation" 命令在 Stata 命令行中可用。 使用 sgmediation 插件的步骤如下:1. 安装插件:将解压后的 "sgmediation" 文件放入 Stata 的 ado 目录。如果 Stata 安装路径是 C:\Program Files\Stata\ado\base,则需将文件复制到 C:\Program Files\Stata\ado\base\s。2. 启动 Stata:打开 Stata,确保软件已更新至最新版本,以便识别新添加的 ado 文件。3. 加载插件:启动 Stata 后,在命令行输入 ado update sgmediation,以确保插件已加载并更新至最新版本。4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值