比赛 20220531高一小测验 评测结果 AAAAAAAAAA
题目名称 素数环 最终得分 100
用户昵称 op_组撒头屯 运行时间 0.871 s
代码语言 C++ 内存使用 3.44 MiB
提交时间 2022-06-01 20:07:34
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=20+5;
bool ok[]={0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0};
int n,s=0;
int a[N]={0};
bool vis[N]={0};
void dfs(int pt){
    if (pt==n+1){
        if (ok[a[1]+a[n]]==0)return ;
        for (int i=1;i<=n;i++)printf("%d ",a[i]);
        printf("\n");
        return ;
    }
    for (int i=1;i<=n;i++){
        if (vis[i]==0&&ok[a[pt-1]+i]==1){
            vis[i]=1;a[pt]=i;
            dfs(pt+1);
            vis[i]=0;
        }
    }
    return ;
}
int main(){
    freopen ("primering.in","r",stdin);
    freopen ("primering.out","w",stdout);
    while(scanf("%d",&n)!=EOF){
        printf("Case %d:\n",++s);
        memset(vis,0,sizeof(vis));
        memset(a,0,sizeof(a));
        if (n==1)continue;
        vis[1]=a[1]=1;
        dfs(2);
    }
    return 0;
}