F 牛牛与交换排序
//题目的限制条件是每次选翻转的区间只能更靠右,所以不能用长度为2的区间翻转两次达到把x翻到后面。所以确定k的方法是从左到右找到第一个顺序不对的数字,然后看它的位置和现在位置的距离,因为它一定是由一个这么大的区间翻过来的。
//接下来就按照给定的k去翻,直到不成立为止
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, a[maxn], pos[maxn];
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i = 1; i <= n; i++){
cin>>a[i]; pos[a[i]] = i;
}
int k = 0;
for(int i = 1; i <= n; i++)
if(pos[i]-i!=0){k=pos[i]-i; break;}
for(int i = 1; i <= n; i++){
if(a[i]==i)continue;
if(a[i+k]!=i){
cout<<"no"; return 0;
}
reverse(a+i,a+pos[i]+1);
}
cout<<"yes\n"<<k+1<<"\n";
return 0;
}
H 牛牛与棋盘
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b){return !b?a:gcd(b,a%b);}
int main(){
int n; cin>>n;
for(int i = 1; i <= n; i++){
bool x;
if(i%2==1)x = 0;
else x = 1;
for(int j = 1; j <= n; j++){
cout<<x; x = !x;
}
cout<<"\n";
}
return 0;
}
I 牛牛的“质因数”
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 4e6+10;
const LL mod = 1e9+7;
bitset<maxn>p;
LL pows[11] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000};
LL ma[maxn];
int main(){
ios::sync_with_stdio(false);
int n; cin>>n;
//map<int,string>ma;
//map<LL,LL>ma;
for(int i = 2; i <= n; i++){
if(p[i])continue;
//ma[i] = to_string(i);
ma[i] = i;
for(int j = 2*i; j <= n; j+=i){
p[j] = 1;
int k = 0, kk = i;
while(kk > 0){k++; kk /= 10;}
int t = j;
while(t%i==0){
//ma[j] += to_string(i);
ma[j] = (ma[j]*pows[k]%mod+i)%mod;
t /= i;
}
}
}
LL ans = 0;
//for(auto i : ma){
for(int i = 2; i <= n; i++){
//cout<<i.first<<" "<<stoi(i.second)<<"\n";
//ans += stoi(i.second)%mod;
//cout<<i.first<<" "<<i.second<<"\n";
//ans = (ans+i.second)%mod;
ans = (ans+ma[i])%mod;
}
cout<<ans%mod<<"\n";
return 0;
}
J 牛牛想要成为hacker
//不能组成三角形不就好了??
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int f[110];
int main(){
int n; cin>>n;
f[0] = 1; f[1] = 2; cout<<"2 ";
for(int i = 2; i <= min(40,n); i++){
f[i] = f[i-1]+f[i-2];
cout<<f[i]<<" ";
}
for(int i = 41; i <= n; i++)
cout<<"1 ";
return 0;
}