感觉自己在瞎搞。
A:
题意:给你l到r的数,写下他们各自的除数,除了1,问出现次数最多的数
思路:如果l!=r那必然是2嘛,如果l==r,就是l
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
int l,r;
scanf("%d%d",&l,&r);
if(r == l)
printf("%d\n",r);
else
printf("2\n");
return 0;
}
B:
题意:写出一个字符串只有ab,尽量少c,串中不能出现长度为3的回文串。
思路:aabb…
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
char s[6] = "aabb";
int main()
{
int n;
scanf("%d",&n);
if(n < 4)
{
for(int i = 0 ; i < n ; i++)
cout<<s[i];
cout<<endl;
}
else
{
int k = n/4;
for(int i = 0; i < k ; i++)
cout<<s;
for(int i = 0; i < n%4;i++)
cout<<s[i];
cout<<endl;
}
return 0;
}
C:
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
int n;
scanf("%d",&n);
if(n%2 == 0)
printf("%d\n",n/2-1);
else
printf("%d\n",n/2);
return 0;
}
D:
将字符串中间的ab换成bba,直到不能换为止,其实就是求最终变成bbbbaaaaa最小的次数,从后往前扫一遍即可,单看每个a就看它后面的b有几个,而每个a往后走,都会给前面的a增加numb的b的数量
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 1000005;
LL data[maxn];
LL m = 1000000007;
char s[maxn];
int main()
{
scanf("%s",s);
int slen = strlen(s);
LL ans = 0;
int sizea = 0,sizeb = 0;
LL last = 0;
for(int i = slen-1 ; i >= 0; i--)
{
if(s[i] == 'a') sizea++;
else sizeb++;
if(s[i] == 'a')
{
LL th = sizeb;
ans = (ans+th)%m;
sizeb = (sizeb+ th)%m;
}
}
cout<<ans<<endl;
return 0;
}
E/F F题现在是不会的,E题。。题意我没能完全理解,看完了cf上的题解和网上能找到的。。都没能理解T树给的边到底有什么用。之后看能不能补。