社区讨论
求助,开了O2AC,不开TLE最后一个点
P1219[USACO1.5] 八皇后 Checker Challenge参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lo7ttue0
- 此快照首次捕获于
- 2023/10/27 07:39 2 年前
- 此快照最后确认于
- 2023/10/27 07:39 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
int ans[15],num,xy,p=0;
bool check(int n){
for(int i=0;i<n;i++){
if((ans[i]==ans[n])||(abs(ans[i]-ans[n])==abs(n-i))){
return false;
}
}
return true;
}
void print(int x){
if(x==xy){
num++;
if(p<3){
for(int i=0;i<xy;i++){
cout<<ans[i]+1<<' ';
}
cout<<endl;
p++;
}
}
for(int i=0;i<xy;i++){
ans[x]=i;
if(check(x)){
print(x+1);
}
}
}
int main(){
cin>>xy;
print(0);
cout<<num;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...