2021牛客寒假算法基础集训营2,签到题FHIJ

举报
小哈里 发表于 2022/05/10 23:43:02 2022/05/10
【摘要】 F 牛牛与交换排序 //题目的限制条件是每次选翻转的区间只能更靠右,所以不能用长度为2的区间翻转两次达到把x翻到后面。所以确定k的方法是从左到右找到第一个顺序不对的数字,然后看它的位置和现在位置的距...

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;
}


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

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;
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

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;
}


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

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;
}


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。

原文链接:gwj1314.blog.csdn.net/article/details/113663153

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。