2019年蓝桥杯B组

第五题(迷宫)

眼睛都瞅瞎了

#include<bits/stdc++.h>
using namespace std;
int divs[4][2] = {{0,1},{-1,0},{1,0},{0,-1}};  //x0y1; 
struct pin{
	int x,y;
	char cdivs;
}stapin[35][55];
bool vis[35][55]={0};
int main(){
	queue<pin> q;
	int i,j;
	char maps[35][55];
	for(i=1; i<=30; i++){
		for(j=1; j<=50; j++){
			scanf("%c",&maps[i][j]);
		}
		getchar();
	}
	for(i=1; i<=30; i++){
		for(j=1; j<=50; j++){
			stapin[i][j].x=j;
			stapin[i][j].y=i;
		}
	}
	
	q.push(stapin[1][1]);
	while(!q.empty()){
		struct pin np = q.front();
		q.pop();
		vis[np.y][np.x]=1;
		for(i=0;i<4;i++){
			int newy=np.y+divs[i][1],newx=np.x+divs[i][0];
			if(newx>=1&& newx<=50 && newy>=1 && newy<=30){
				if(maps[newy][newx]!='1'&& vis[newy][newx]!= 1){
					vis[newy][newx]=1;
					if(i==0){
						stapin[newy][newx].cdivs='D';
					}else if(i==1){
						stapin[newy][newx].cdivs='L';
					}else if(i==2){
						stapin[newy][newx].cdivs='R';
					}else if(i==3){
						stapin[newy][newx].cdivs='U';
					}
					q.push(stapin[newy][newx]);
				}
			}
		}
		
	}
//	for(i=1; i<=30; i++){
//		for(j=1; j<=50; j++){
//			cout << stapin[i][j].cdivs;
//		}
//		cout << endl;
//	}
//	printf("-------\n");
	string ans;
	q.push(stapin[30][50]);
	while(!q.empty()){
		struct pin np = q.front();
		q.pop();
		ans=ans+np.cdivs;
		if(np.cdivs=='D'){
			q.push(stapin[np.y+divs[3][1]][np.x+divs[3][0]]);
		}else if(np.cdivs=='L'){
			q.push(stapin[np.y+divs[2][1]][np.x+divs[2][0]]);
		}else if(np.cdivs=='R'){
			q.push(stapin[np.y+divs[1][1]][np.x+divs[1][0]]);
		}else if(np.cdivs=='U'){
			q.push(stapin[np.y+divs[0][1]][np.x+divs[0][0]]);
		}
		
	}
	reverse(ans.begin(),ans.end());
	cout << ans;
	return 0;
}

第八题

#include<bits/stdc++.h>
using namespace std;
long long int a[100005];
int gcd(int a,int b){
	return b? gcd(b,a%b) : a;
}
int main(){
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	
	long long d=a[1]-a[0];
	int num=n,j,flag=1,z=2;
	while(num!=0){
		num=n-1;
		
		for(i=1; i<n; i++){
			if(d==0){
				printf("%d",n);
				return 0;
			}
			if((a[i]-a[0])%d==0){
				num--;
			}
		}
		if(num==0){
			break;
		}
		if(z<=n){
//			printf("%d\n",d);
			d=gcd(d,a[z]);      //  90分 
//			d=a[n-z-1]-a[0];	//  30分 
			z++;
		}
		
	}

	printf("%lld",(a[n-1]-a[0])/d +1);
	return 0;
}

第九题

https://www.dtmao.cc/news_show_521471.shtml

第三题

看上去简单的题也要动手写一下

#include<bits/stdc++.h>
using namespace std;
int s[4]={1,1,1};
int main(){
	int sum,i,a=20190324;
	for(i=3;i<a;i++){
		sum=(s[0]+s[1]+s[2])%10000;
		s[0]=s[1];
		s[1]=s[2];
		s[2]=sum;
	}
	cout << s[2];
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值