2021牛客寒假算法基础集训营1，签到题ABFIJ

A 串

//f[i]表示长度为i的有us的串的数量
//有u但是u后面没有s的串的数量：总数-没有u的-有us的
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e6+10;
const LL mod = 1e9+7;
LL pows(LL a, LL b, LL m) {
a %= m;
LL res = 1;
while(b>0){
if(b&1)res=res*a%m;
a = a*a%m;
b >>= 1;
}
return res%m;
}
LL f[maxn];
int main(){
ios::sync_with_stdio(false);
LL n;  cin>>n;
f[2] = 1;
for(LL i = 3; i <= n; i++){
f[i] = pows(26,i-1,mod)-pows(25,i-1,mod)+25*f[i-1]%mod;
f[i] = (f[i]+mod)%mod;
}
LL ans = 0;
for(int i = 1; i <= n; i++)
ans = (ans+f[i])%mod;
cout<<ans<<"\n";
return 0;
}



B 括号

//构造q*(q+p)+t
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
ios::sync_with_stdio(false);
int k;  cin>>k;
if(k==0){cout<<"(\n"; return 0;}

string s;
int q = (int)sqrt(k);
for(int i = 1; i <= q; i++)s += '(';
int rest = k-q*q;
for(int i = 1; i <= rest/q; i++)s+='(';
rest %= q;
for(int i = q; i >= 1; i--){
if(i==rest)s += '(';//rest->1个())))
s += ')';
}
cout<<s<<"\n";
return 0;
}



F 对答案一时爽

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5+10;
const LL mod = 1e9+7;
int main(){
ios::sync_with_stdio(false);
int n;  cin>>n;
char s[110];
for(int i = 1; i <= n; i++){
cin>>s[i];
}
int mx = 0, mi = 0;
for(int i = 1; i <= n; i++){
char ch; cin>>ch;
if(ch==s[i])mx+=2;
else mx++;
}
cout<<mx<<" "<<mi<<"\n";
return 0;
}



I 限制不互素对的排列

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5+10;
int vis[maxn];
int gcd(int a, int b){return !b?a:gcd(b,a%b);}
int main(){
ios::sync_with_stdio(false);
LL n, k;  cin>>n>>k;

k++;
vector<int>ans;
//ans.push_back(1); vis[1] = 1;
for(int i = 2; i <= n; i++){
if(k==0)break;
for(int j = i; j <= n; j += i){
//cout<<k<<" "<<j<<"\n";
if(k==0)break;
if(vis[j])continue;
vis[j] = 1;
ans.push_back(j);
k--;
}
if(k==0)break;
if(gcd(i+1,ans.back())>1){
vis[i+1] = 1;
ans.push_back(i+1);
k--;
}else{
k++;
}
}
if(k!=0){cout<<"-1\n"; return 0;}

for(int i = 1; i <= n; i++){
if(!vis[i]){
if(gcd(ans.back(),i)==1)ans.push_back(i);
else{
ans.insert(ans.begin(),i);
}
}
}
for(int i = 0; i < ans.size(); i++)
cout<<ans[i]<<" ";
return 0;
}



J 一群小青蛙呱蹦呱蹦呱

//具有2种以上不同类型的质因子，筛除每个质因子，求最高次。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e8+10;
const LL mod = 1e9+7;
bitset<maxn>p;
int main(){
ios::sync_with_stdio(false);
int n;  cin>>n;
if(n<=5){cout<<"empty\n"; return 0;}

for(int i = 2; i*i <= n; i++){
if(p[i])continue;
for(int j = 2*i; j <= n; j+=i)
p[j] = 1;
}

//p!=2:至少两个质因子,最大时因子为2,n==2*p^k
LL ans = 1;
for(int i = 3; i <= n/2; i++){
if(p[i])continue;
LL now = i;
while(now*i <= n/2)now *= i;//最高次
ans *= now;  ans %= mod;
}
//p==2:最大时因子为3，n==3*2^k
n /= 3;
while(n>>=1){ ans *= 2; ans %= mod;}
cout<<ans<<"\n";
return 0;
}


02-04 99
02-19 1527
02-06 2464
02-04 396
04-05 1万+
12-31