第六届蓝桥杯b组省赛--备战蓝桥杯版h

0奖券数目 - 蓝桥云课

简单模拟一下统计出里面不带4的数字

cpp 复制代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int cnt=0;
bool check(int x)
{
	while(x)
	{
		if(x%10==4)return false;
		x/=10;
	}
	return true;
}

int main()
{
	for(int i=10000;i<=99999;i++)
	{
		if(check(i))
		{
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
} 

0星系炸弹 - 蓝桥云课

日期问题--》日期模板解决

cpp 复制代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	bool began=false;
	int cnt=0;
	for(int y=2014;y<=2018;y++)
	{
		for(int m=1;m<=12;m++)
		{
			for(int d=1;d<=31;d++)
			{
				if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
				{
				}
				else if(m==2)
				{
					if((y%4==0&&y%100!=0)||(y%400==0))
					{
						if(d>29)continue;
					}
					else
					{
						if(d>28)continue;
					}
				}
				else
				{
					if(d>30)continue;
				}
				
				if(y==2014&&m==11&&d==9)
				{
					began=true;
					continue; 
				}
				if(began)
				{
					cnt++;
					if(cnt==1000)
					{
						printf("%04d-%02d-%02d",y,m,d);
						return 0;
					}
				}
			}
		}
	}
	return 0; 
}

0三羊献瑞 - 蓝桥云课

暴力多个循环-》但是要注意的是去重

cpp 复制代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    for(int a=0;a<=9;a++)
    for(int b=0;b<=9;b++)
    for(int c=0;c<=9;c++)
    for(int d=0;d<=9;d++)
    for(int e=0;e<=9;e++)
    for(int f=0;f<=9;f++)
    for(int g=0;g<=9;g++)
    for(int h=0;h<=9;h++)
    {
        // 判断数字互不相同
        if(a==b||a==c||a==d||a==e||a==f||a==g||a==h) continue;
        if(b==c||b==d||b==e||b==f||b==g||b==h) continue;
        if(c==d||c==e||c==f||c==g||c==h) continue;
        if(d==e||d==f||d==g||d==h) continue;
        if(e==f||e==g||e==h) continue;
        if(f==g||f==h) continue;
        if(g==h) continue;
        
        // 首位不能为 0
        if(a==0 || e==0) continue;
        
        int x = a*1000 + b*100 + c*10 + d;
        int y = e*1000 + f*100 + g*10 + b;
        int z = e*10000 + f*1000 + c*100 + b*10 + h;
        
        if(x + y == z)
        {
            cout << e << f << g << b << endl;  // 输出"三羊献瑞"
            return 0;
        }
    }
    return 0;
}

0移动距离 - 蓝桥云课

bfs--》求出最短距离

cpp 复制代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=1000;
int w,s,e;
int dist[N][N];
int sx,sy,ex,ey;
int n;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};

int bfs()
{
	memset(dist,-1,sizeof dist);
	queue<pair<int,int>> q;
	q.push({sx,sy});
	dist[sx][sy]=0;
	while(!q.empty())
	{
		auto t=q.front();q.pop();
		int x=t.first;
		int y=t.second;
		for(int k=0;k<4;k++)
		{
			int nx=x+dx[k];
			int ny=y+dy[k];
			if(nx>=1&&nx<=n&&ny>=1&&ny<=w&&dist[nx][ny]==-1)
			{
				dist[nx][ny]=dist[x][y]+1;
				q.push({nx,ny});
			}
		}
	}
	return dist[ex][ey];
}

int g[N][N];

int main()
{
	cin>>w>>s>>e;
	int k=1;
	n=10000/w+1;
	for(int i=1;i<=n;i++)//hang
	{
		if(i%2!=0)
		{
			for(int j=1;j<=w;j++)
			{
				g[i][j]=k++;
			}
		}
		else
		{
			for(int j=w;j>=1;j--)
			{
				g[i][j]=k++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(g[i][j]==s)
			{
				sx=i;
				sy=j;
			}
			if(g[i][j]==e)
			{
				ex=i;
				ey=j;
			} 
		}
	}
	int res=bfs();
	cout<<res<<endl;
	return 0;
}

0垒骰子 - 蓝桥云课

dfs注意骰子的相对面可以用数组来反映,并且可以用二维数组表示是否冲突

cpp 复制代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int MOD=10e9+7;
typedef long long ll;

int n,m;
bool conflict[7][7];
int op[7]={0,4,5,6,1,2,3};

ll ans=0;
int side[7]={0,4,4,4,4,4,4};

void dfs(int depth,int last)
{
	if(depth==n)
	{
		ll ways=1;
		for(int i=0;i<n;i++)
		{
			ways=(ways*4)%MOD;
		}
		ans=(ans+ways)%MOD;
		return;
	}
	
	for(int top=1;top<=6;top++)
	{
		if(depth==0)
		{
			dfs(depth+1,top);
		}
		else
		{
			int lastbottom=op[last];
			if(!conflict[lastbottom][top])
			{
				dfs(depth+1,top);
			}
		}
	}
}

int main()
{
	cin>>n>>m;
	memset(conflict,false,sizeof conflict);
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		conflict[a][b]=true;
		conflict[b][a]=true; 
	}
	dfs(0,0);
	cout<<ans%MOD<<endl;
	return 0; 
}

 

0生命之树 - 蓝桥云课

cpp 复制代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100010,M=2*N; 

typedef long long ll;
int n;
ll a[N];
ll dp[N];
ll ans=-1e18;

int h[N],e[M],ne[M],idx;

void add(int a,int b)
{
	e[idx]=b;
	ne[idx]=h[a];
	h[a]=idx++; 
}

void dfs(int x,int fa)
{
	dp[x]=a[x];
	
	for(int i=h[x];i!=-1;i=ne[i])
	{
		int v=e[i];
		if(v==fa)continue;
		dfs(v,x);
		if(dp[v]>0)
		{
			dp[x]+=dp[v];
		}
	}
	ans=max(ans,dp[x]);
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	memset(h,-1,sizeof h);
	for(int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		add(a,b);
		add(b,a);
	}
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
}

 
相关推荐
List<String> error_P12 小时前
蓝桥杯最后几天冲刺:暴力大法(一)
算法·职场和发展·蓝桥杯
Tanecious.13 小时前
蓝桥杯备赛:Day6-B-小紫的劣势博弈 (牛客周赛 Round 85)
c++·蓝桥杯
迈巴赫车主13 小时前
蓝桥杯3500阶乘求和java
java·开发语言·数据结构·职场和发展·蓝桥杯
wljy114 小时前
第十三届蓝桥杯大赛软件赛省赛C/C++ 大学 B 组(个人见解,已完结)
c语言·c++·算法·蓝桥杯·stl
Tanecious.1 天前
蓝桥杯备赛:Day7- P10424 [蓝桥杯 2024 省 B] 好数
c++·蓝桥杯
List<String> error_P1 天前
蓝桥杯最后冲刺暴力(二)
职场和发展·蓝桥杯
yoyobravery1 天前
蓝桥杯第13届单片机(满分)
单片机·蓝桥杯
Tanecious.1 天前
蓝桥杯备赛:Day7- U535982 C-小梦的AB交换
c语言·c++·蓝桥杯
迈巴赫车主2 天前
蓝桥杯19724食堂
java·数据结构·算法·职场和发展·蓝桥杯