跳到正文

个人记录

2024/10/08模拟赛总结

fly_bamboo约 5 分钟
原文
文章信息与版本

文章信息

发布
2024年10月8日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 5 分钟

版本

  1. v1当前

OK啊勇夺第 33 !

T1~T3 AC!

T4

考场上居然忘记了 DFS,没来得及。
这道题可以提前预处理斐波那契数列,然后 DFS 枚举如何分解这个数,调了一会发现只要处理到斐波那契数列的第 8585 项就够了。
注意不要把 11 放进去,否则会陷入疯狂÷ 11 的死循环。
正确代码:

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[100005];
int a[100005],cnt=0;
void dfs(int x,int lst)
{
	if(x==1)
	{
		cnt++;
		return;
	}
	for(int i=lst;i<=85;i++)
	{
		if(x%a[i]==0) dfs(x/a[i],i);
	}
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	a[1]=2;
	a[2]=3;
	for(int i=3;i<=85;i++) a[i]=a[i-2]+a[i-1];
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		cnt=0;
		dfs(n,1);
		cout<<cnt<<endl;
	}
	return 0;
}

T5,AC!

T6

纯属时间没把握好,没有时间写了,是想到了思路的。
跑两边 BFS。
第一遍用一个数组来记录贝西走到每个灌木的步数,因为我们无法确定贝西走到最近的一个灌木是否是最优答案,所以全部枚举一遍。
第二遍从骑士出发,求出骑士到每个灌木丛的答案,那么最短路就是贝西到这个灌木的距离+骑士到这个灌木的距离,一个 minnminn 记录答案就可以啦!
代码:

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int a[1005][1005];
bool vis[1005][1005];
int ans[1005][1005];
int qx,qy,mx,my;
int head=0,tail=1;
int minn=1e18;
struct node
{
	int x,y,step;
}q[1000005];
vector<node> op;
bool check(int x,int y)
{
	if(x<1||x>n||y<1||y>m) return false;
	if(vis[x][y]==true||a[x][y]==1) return false;
	return true;
}
void work(int x,int y,int step)
{
	if(check(x,y)==true)
	{
		head++;
		q[head].x=x;
		q[head].y=y;
		q[head].step=step;
		vis[x][y]=true;
		if(ans[x][y]>0) minn=min(minn,ans[x][y]+step);
		if(a[x][y]==4) ans[x][y]=step;
	}
	return;
}
void bfs()
{
	head=0,tail=1;
	head++;
	q[head].x=qx;
	q[head].y=qy;
	q[head].step=0;
	vis[qx][qy]=true;
	while(head-tail+1>0)
	{
		int x=q[tail].x;
		int y=q[tail].y;
		int step=q[tail].step;
		tail++;
		work(x-1,y,step+1);
		work(x+1,y,step+1);
		work(x,y-1,step+1);
		work(x,y+1,step+1);
	}
	return;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>m>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
			if(a[i][j]==2) qx=i,qy=j;
			if(a[i][j]==3) mx=i,my=j;
			ans[i][j]=1e18;
		}
	}
	bfs();
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) vis[i][j]=false;
	}
	qx=mx,qy=my;
	bfs();
	cout<<minn;
	return 0;
}

OK啊发挥超常!

原文