蓝桥杯8天复习(day1)

1、空间(21年省赛——3月14日) 

        注意:一个字节等于8个bit

#include <iostream>
using namespace std;
int main()
{
  cout<<256*1024*1024/4;
  return 0;
}


2、等差数列(19年省赛——3月12日) 

        注意:这道题用差分+gcd求公差,不用gcd可能会导致后续某个数不在数列中(当时我没用gcd),这次我又踩了一次坑:常数列,记住特判!!!

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
LL a[100005];
LL n,d;

int gcd(LL a,LL b) {
	return b==0?a:gcd(b,a%b);
}

int main() {
	cin>>n;
	for(int i=0; i<n; i++)
		cin>>a[i];
	sort(a,a+n);
	d=a[1]-a[0];
	if(d==0) cout<<n;
	else {
		for(int i=2; i<n; i++)
			d=gcd(d,a[i]-a[i-1]);
		cout<<(a[n-1]-a[0])/d+1;
	}
	return 0;
}


3、回文日期(20年省赛——3月9号)

注意:坑点在输入、回文和ABABBABA的区别以及前导0。

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
int date[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int n,f1,f2;

int main() {
	cin>>n;
	for(int i=n+1; i<=99991231; i++) {
		int year=i/10000;
		if(year%400==0 || (year%4==0 && year%100!=0)) date[2]=29;
		else date[2]=28;
		int month=i%10000/100,day=i%100;
		//合法日期 
		if(month<=0 || month>12 || day<=0 || day>date[month]) continue;
		int yy=year,res=0,nn=month*100+day;
		//将年倒过来 
		while(year) {
			res=res*10+year%10;
			year/=10;
		}
		//第一个回文日期 
		if(res==nn && !f1) {
			printf("%04d%04d\n",yy,nn);//不足4位补0(防止前导0没了) 
			f1=1;
		}
		//第一个ABABBABA 
		if(res==nn && !f2 && (yy/1000)==(yy%100/10) && (yy%1000/100)==(yy%10)) {
			printf("%04d%04d\n",yy,nn);
			f2=1;
		}
		//输出完啦,快跑~ 
		if(f1 && f2) break;		
	}
	return 0;
}


4、青蛙跳杯子(17年省赛——3月18日)

注意:这里的W和B就是摆设,不需要管。这道题没什么坑,再做一遍也没什么太大波澜。

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
set<string> se;
const int dz[]= {-3,-2,-1,1,2,3};
string s1,s2;
int n,z,nz;

struct node {
	string s;
	int dis;
	node (string s,int dis):s(s),dis(dis) {}
};

queue<node> q;
void bfs() {
	node u(s1,0);
	se.insert(s1);
	q.push(u);
	while(!q.empty()) {
		node u=q.front();
		q.pop();
        //结束
		if(u.s==s2) {
			cout<<u.dis;
			return;
		}
        //找空格
		for(int i=0; i<u.s.size(); i++)
			if(u.s[i]=='*') {
				z=i;
				break;
			}
        //遍历
		for(int i=0; i<6; i++) {
			nz=z+dz[i];
            //范围是0~n-1
			if(nz<0 || nz>=n) continue;
            //交换
			string ss=u.s;
			ss[z]=u.s[nz];
			ss[nz]=u.s[z];
            //判重
			if(!se.count(ss)) {
				se.insert(ss);
				int diss=u.dis+1;
				node v(ss,diss);
				q.push(v);
			}
		}
	}
}

int main() {
	cin>>s1>>s2;
	n=s1.size();
	bfs();
	return 0;
}

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_谦言万语

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值