进阶22:输出该字符串最多能断成多少截完全一样的子串,样例输入abcabcabcabc样例输出4,最多能断成四个"abc",也就是abc重复四遍便是原串,同时也能断成两个"abcabc",最坏情况是断成一个原串"abcabcabcabc"。
- 思路:最大的截断数是按1分割,所以输出最大截断数量只需要从1递增,第一个符合截断串完全一致的即为答案。最大值为字符串的一半和字符串长度本身。
- 代码错误:1.字符串的遍历步长为i+=cur而非i++,2. 用cur=3作为初值来测试题目,提交时没有改。
cpp
#include <bits/stdc++.h>
using namespace std;
bool Check2(int index1,int index2,string &s1){
int len = index2 - index1;
for(int i=0;i<len;i++){
if(s1[index1] != s1[index2])return false;
index1++;index2++;
}
return true;
}
bool Check(int &cur,string &s1){
for(int i=0;i<s1.size()-cur;i+=cur){
if(Check2(i,i+cur,s1) == false)return false;
}
return true;
}
int main(){
string s1;
cin>>s1;
int cur=1;
int ans=0;
while(cur<s1.size()/2){
if(Check(cur,s1)){
ans=cur;
break;
}
cur++;
}
//cout<<ans<<endl;
if(ans)cout<<s1.size()/ans<<endl;
else{
cur=s1.size()/2;
if(Check(cur,s1))cout<<s1.size()/cur<<endl;
else cout<<s1.size()/s1.size()<<endl;
}
system("pause");
}
//abcabcabcabc
Generative artificial intelligence refers to a class of AI technologies that can generate new content such as text, images, and audio. Unlike traditional discriminative models, generative models learn the distribution of data and produce new samples based on learned patterns. In recent years, with the advancement of deep learning techniques, generative models have achieved significant progress in many fields. For instance, generative adversarial networks and large language models are capable of producing high-quality images and natural language text. These technologies have broad application prospects in areas such as content creation, intelligent assistants, and virtual reality. However, generative AI also introduces challenges such as the spread of misinformation and copyright protection issues. Therefore, how to strengthen regulation while promoting technological development has become an important research topic.
- 生成式人工智能是指人工智能的一个能生成诸如文本图片或音频的新内容的类别。不同于传统的判别式模型,生成式模型学习数据的分配并生成基于已学习模式的新样本。在近年来,伴随着深度学习技术的发展,生成式模型已在许多领域取得了显著的进步。例如,生成式对抗网络和大语言模型它们能生成高质量的文本和自然语言文本。这些技术有广阔的应用前景在例如内容生成、智能助理和虚拟现实这些领域。然而,生成式人工智能也引发了例如错误信息的扩散和版权保护问题。从而,如何在推动技术发展的同时强化监管已经成为了一个重要的研究话题。
- refers to 指的是/参考/引用、discriminative 判别式、adversarial 对抗的