Codeforces Round #506 (Div. 3)
A.Many Equal Substrings
这个题就是给了你两个数字,第一个代表的是字符串的长度,第二个代表的就是要把这个字符串出现多少次,然后我们看的两组测试样例发现,第二组直接写就可以,但是第一组我们发现如果他的前面和后面有了相同的东西,那么他是可以把前一个的后缀当成后一个的前缀,所以我们就是要先对这个字符串进行一个判断,看看前后缀是否相等,因为这个题的数据范围比较小,所以我们是可以直接暴力的,这题好像也可以用KMP做,但是我还是不太会,等学会了回来补上这个方法
所以上代码
#include<bits/stdc++.h>
#define int long long
#define BUFF ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
signed main()
{
/*
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
*/
int n,k;
n=read(),k=read();
string s;
cin>>s;
int temp=0;
for(int i=0;i<n;i++)
{
if(s.substr(0,i)==s.substr(n-i,i))
{
temp=i;
}
}
cout<<s;
k--;
while(k--)
{
cout<<s.substr(temp);
}
puts("");
return 0;
}
然后这里又用到了另一个的知识点就是,substr这个函数,然后这个函数有两种常用的用法
第一种就是
里面只有一个参数,所代表的意思就是从这个参数代表的下标开始,一直到字符串的结尾
string s="0123456789";
cout<<s.substr(5);
//56789
第二种就是
里面有两个参数,所代表的意思就是从第一个参数的位置开始,截取第二个参数为长度的一个字符串
string s="0123456789";
cout<<s.substr(5,3);
//567
这个就是简单的substr的用法
B.Creating the Contest
这个题还是比较好理解的,什么意思呢,就是给你了一个数字,然后再输入n个数字,然后我们就是去找最长的一个序列里面一共有多少个数字,而且题里明确的告诉了我们这个给我们的序列是递增的,所以我们直接跑一边就可以了
#include<bits/stdc++.h>
#define int long long
#define BUFF ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
signed main()
{
/*
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
*/
vector<int>a;
a.clear();
int T;
int n;
n=read();
for(int i=0;i<n;i++)
{
int xx;
xx=read();
a.push_back(xx);
}
int maxx=-1;
int cnt=1;
for(int i=0;i<n-1;i++)
{
if(a[i]*2>=a[i+1])
{
cnt++;
}
else
{
maxx=max(maxx,cnt);
cnt=1;
}
}
maxx=max(maxx,cnt);
printf("%lld",maxx);
puts("");
return 0;
}