水题求调
  • 板块学术版
  • 楼主zxh_qwq
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/5/13 07:52
  • 上次更新2023/10/23 15:58:16
查看原帖
水题求调
919709
zxh_qwq楼主2023/5/13 07:52

rt,题目link

代码

#include<bits/stdc++.h>
using namespace std;
bool c[11];
int n,m;
void f(int t){
	bool flag=true;
	if(n==1){
		cout<<"Move the "<<m<<"th ring ";
		if(c[1]==0)cout<<"up"<<endl;
		else cout<<"down"<<endl;
	}
	for(int i=1;i<n-1;i++){
		if(c[i]==1)flag=0;
	}
	if(c[t-1]==0)flag=0;
	if(flag){
		c[t]=!c[t];
		cout<<"Move the "<<t+m<<"th ring ";
		if(c[t]==1)cout<<"up"<<endl;
		else cout<<"down"<<endl;
		f(t-2);
		f(t-1);
	}
}
int main(){
	memset(c,1,sizeof(c));
	int a;
	cin>>a;
	cin>>n>>m;
	n-=m;
	cout<<"Start moving!"<<endl;
	f(n);
	cout<<"End moving!"<<endl;
	return 0;
} 
2023/5/13 07:52
加载中...