Periodic Strings

UVa455 Periodic Strings 最小周期串 题意 给你一个字符串 问你字符串的最小周期串,题意很简单 “abcabcabcabc”周期为3-abc 6-abcabc 12-自己 最小周期串为3 周期串性质 之前做过一次,这次又错了 整理下 字符串s,设k为周期,长度为len, 满足:len%k==0 周期与长度的关系 s[i] == s[i%k] 第i个字符一定与i%k个字符相同,i%k表示第一个周期里的第i%... 阅读详情

Description
Download as PDF
Periodic Strings
A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, the string “abcabcabcabc” has period 3, since it is formed by 4 repetitions of the string “abc”. It also has periods 6 (two repetitions of “abcabc”) and 12 (one repetition of “abcabcabcabc”).
Write a program to read a character string and determine its smallest period.
Input
The first line oif the input file will contain a single integer N indicating how many test case that your program will test followed by a blank line. Each test case will contain a single character string of up to 80 non-blank characters. Two consecutive input will separated by a blank line.
Output
An integer denoting the smallest period of the input string for each input. Two consecutive output are separated by a blank line.
Sample Input
1

HoHoHo
Sample Output
2
一个字符串,问最少是多少个字符重复的。只用搜n/2次就好了,如果都不行,就是原来的长度。
写的时候要注意比较,容易出错。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
char a[105], b[105];
int check(int x,int step)
{
    int i, j, leap = 0;
    for (i = 1; i < step; i++)
    {
        for (j = i*x ; j < i*x + x; j++)
        {
            if (a[j] != a[j%x])leap = 1;
        }
    }
    if (leap)return 0;
    else return 1;
}
int main()
{
    int i, j, m, n, ans, t, len,step;
    cin >> t;
    getchar(); getchar();
    while (t--)
    {
        gets(a);
        len = strlen(a);
        for (i = 1; i <= len / 2; i++)
        {
            if (len%i != 0)continue;
            step = len / i;
            for (j = 0; j < i; j++)
                b[j] = a[j];
            if (check(i, step))break;
        }
        if (i == len / 2 + 1)cout << len << endl;
        else cout << i << endl;
        if (t != 0)cout << endl;
        if (t)getchar();
    }
    return 0;
}
TIA西门子博途V19安装教程及注意事项 阅读详情

相关推荐

LatentSync:开源数字人唇形同步技术的实战部署与优化指南

本文详细介绍了开源数字人唇形同步工具LatentSync的实战部署与优化全流程。从核心原理(潜在扩散模型与TREPA技术)解析,到手把手完成环境搭建、模型获取及首次推理。文章深入探讨了自定义素材处理、关键参数调优(如guidance_scale),并提供了显存不足、人脸检测失败等常见问题的解决方案与性能优化技巧,旨在帮助用户高效部署并提升生成效果。

9o8p7i6u5y的博客 1004

周期串(Periodic Strings)

第二次的思路是整个字符串都放在一个数组里面,然后用length记录重复串的长度,前length个字符就是重复串,而count记录暂时相同的的字符串长度,然后一一比较,一旦出现不同length就加上count(count为0就加1)如果一个字符串可以由某个长度为k的字符串重复多次得到,则称该串以k为周期。第一次的思路是一个字符数组记录暂时重复的字符串,另一个是记录和上一个字符数组相同部分的字符串,一旦出现不同,就把第二个字符串接到第一个上面去。最后一个就是我路上想出来的,上一个代码并不适用的测试点。

Fool256353的博客 643

ROS下UR+Realsense相机进行手眼标定

手眼标定主要是用来确定相机坐标系和机械臂坐标系之间的转换关系,从而实现后续的抓取等任务。

weixin_42157689的博客 7569

周期串(Periodic Strings)

Description 如果一个字符可以由某个长度为k的字符串重复多次得到,则称该字符串以k为周期。例如,abcabcabc以3为周期(注意,他也以6和12为周期)。 input 1 hohoho output 2 思路分析:和环装序列的思路一样,找到第一个i满足的条件的就为它的最小周期。附上代码,已经经过UVAoj测试。 #include #include #incl

sayniceoh的博客 2263

Ubuntu升级遇到grub-efi-amd64-signed报错?3步搞定这个烦人的EFI目录问题

本文详细解析了Ubuntu系统升级时遇到的“grub-efi-amd64-signed”报错及“cannot find EFI directory”问题。通过剖析UEFI启动机制与EFI系统分区原理,提供了从诊断到修复的三步解决方案,帮助用户快速解决因EFI目录未挂载导致的升级中断,确保系统引导正常。

assembly8low的博客 584

2021秋-北邮计算机导论期末考试(BUPT)

2021秋-北邮计算机导论期末考试(BUPT) 难度较低适合新手练习

weixin_73985779的博客 1496

第四题 UVA455 Periodic Strings

UVA455 Periodic Strings A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, the string ”abcabcabcabc” ...

苦鬼·。 301

一篇文章将三极管讲透:三极管从原理到应用,从参数到特性,从入门到精通

晶体三极管(Transistor)是一种半导体电子器件,也是电子工程中最基本的元件之一。它有三个区域,分别是P型半导体,N型半导体和P型半导体,从而形成PNP型晶体三极管或者NPN型晶体三极管。

学习帮的博客 9万+

Uva 455 Periodic Strings

A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, the string ”abcabcabcabc” has period 3, since it i

DTL66的博客 490

079、LVGL基础控件:消息框(Msgbox)

《LVGL消息框控件深度解析与避坑指南》 文章深入剖析了LVGL消息框控件的核心特性和使用技巧。消息框本质是带按钮的模态容器,而非独立窗口。作者分享了创建消息框的正确姿势、标题/内容设置方法、安全的按钮事件处理方式(避免直接调用close函数导致栈溢出),并详细介绍了模态/非模态实现、样式自定义、动态更新等实用技巧。针对常见问题如内存管理、按钮数量限制、动画效果等给出了专业建议,特别强调了消息框作为用户交互关键环节的优化重要性,建议通过异步删除、合理父对象选择等方式提升稳定性。文章包含大量实际项目经验总结,

m0_50546716的博客 152

RSA算法详解:万字文章详解RSA的加密与解密

为了彻彻底底的研究明白RSA算法,真的是。。煞(lei)费(si)苦(wo)心(le),首先我希望自己前前后后、彻彻底底的琢磨明白,其次我也希望我把他分享出来以后,大家都能读得懂,这篇文章真的是我迄今为止写的又臭又长的一篇文章了,但是我能保证的是,你读完了以后,绝对不会再问RSA是啥玩意儿了。。

布啦啦 7667

【UVA】 455 --- Periodic Strings

【UVA】 455 --- Periodic Strings A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, the string ”abcabcab...

来日浅谈的博客 423

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

UVA - 455 Periodic Strings

UVA - 455 Periodic Strings 题目大意。给一段循环字符串然后求该字符串最小重复子串解题思路:求因子,然后因子从小到大一个一个试,试到了就直接break,不然会被刷新,别问我怎么知道的。。。

mydjrzal2的博客 329

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

UVA-455 Periodic Strings

UVA - 455 Periodic Strings 题目大意:一个字符串可以由某个长度为 k 的字符串重复得到,求最小周期 k 。如 abcabcabc 的周期为 3。 解题思路:从周期 1 开始枚举,比较相邻两个周期是否对应相同,遍历结束输出。

振丿Love 337

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

UVa 455 - Periodic Strings解题报告

UVa OJ 455 Periodic Strings A character string is said to have periodkif it can be formed by concatenating one or more repetitions of another string of lengthk. For example, the string ...

weixin_30411239的博客 144

UVA 455 Periodic Strings(字符串的循环节)

UVA 455 Periodic Strings A character stringis said to have periodk if it can be formed by concatenating one or morerepetitions of anotherstring of lengthk. For example, the string”abcabcabcabc” has p

Shyazhut 727

UVA455 周期串 Periodic Strings

1HoHoHo。

2401_85048117的博客 195

UVa455-Periodic Strings

UVa455-Periodic Strings思路:因为字符串长度很短,所以可以暴力。从长度1开始把长度可以整除的往后滑动比较,找到第一个符合条件的输出代码:#include <bits/stdc++.h>using namespace std; int judeg(string &s,int n) { int l=s.size(); for(int i=n;i<=l-n;i+=n)

进击的ACMer!!! 628

455 - Periodic Strings

Time limit: 3.000 seconds Problem Description A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, the s...

叶上初阳_285557的博客 277
上一篇: Digit Counting
下一篇: Puzzle
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值