print函数
查看原帖
print函数
691330
Squirrel_GZQ楼主2024/5/18 20:10

这道题为什么我用自写的print会RE,放在搜索函数里面就AC了?

#include<bits/stdc++.h>
using namespace std;
int n,tot,a[100],b[100],c[100],d[100];
//int print(){
//	if(tot<3){
//		for(int x=1;x<=n;x++){
//			cout<<a[x]<<" ";
//		}
//		cout<<endl;
//	}
//	tot++;
//}
void s(int i){
	if(i>n){
		if(tot<3){
		for(int x=1;x<=n;x++){
			cout<<a[x]<<" ";
		}
		cout<<endl;
	}
	tot++;
	}
	else {
		for(int j=1;j<=n;j++){
			if(!b[j]&&!c[i+j]&&!d[i-j+n]){
				a[i]=j;
				b[j]=1;
				c[i+j]=1;
				d[i-j+n]=1;
				s(i+1);
				b[j]=0;
				c[i+j]=0;
				d[i-j+n]=0;
			}
		}
	}
}
int main(){
	cin>>n;
	s(1);
	cout<<tot;
	return 0;
}
2024/5/18 20:10
加载中...