跳到正文

剪贴板

剪贴板 ta5bcm4c

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
using namespace std;
int n,m,i;
long long ans;
struct node
{
	int now,state;			//当前球的位置,传了几次
	node(int a,int b)
	{
		now=a,state=b;
	}
};
queue <node> que;
void bfs(int x,int step)
{
	if(step==m)
	{
		que.push(node(x,step));
		return;
	}
    if(x-(m-step)>1&&x-(m-step)<n)	//判断是不是到不了位置1
    	return;
	if(x==1)
	{
		que.push(node(n,step+1));
		que.push(node(2,step+1));
	}
	else if(x==n)
	{
		que.push(node(n-1,step+1));
		que.push(node(1,step+1));
	}
	else
	{
		que.push(node(x-1,step+1));
		que.push(node(x+1,step+1));
	}
	return;
}
int main()
{
	freopen("ball.in","r",stdin);
	freopen("ball.out","w",stdout);
	for(int n=3;n<=30;n++)
		for(int m=1;m<=30;m++)
		{
          	que.push(node(1,0));
			while(que.front().state!=m)
			{
				bfs(que.front().now,que.front().state);
				que.pop();
			}
			all();
			cout<<ans<<endl;
        }
	return 0;
}