Prime Ring Problem

2020年1月17日 775点热度 0人点赞 0条评论

Prime Ring Problem

时间: 1ms        内存:128M

描述:

A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.

Note: the number of first circle should always be 1.

输入:

n (0 < n < 20).

输出:

The output format is shown as sample below. Each row represents a series of circle numbers in the ring beginning from 1 clockwisely and anticlockwisely. The order of numbers must satisfy the above requirements. Print solutions in lexicographical order.
You are to write a program that completes above process.
Print a blank line after each case.

The followings are programmed codes. Your task is to complete function dfs(). When you submit your program, you just submit only function dfs(). The rest of program will be added to your program automatically.

//The following codes will become the front of your program automatically.
#include<stdio.h>
#include<string.h>
int n,ans[21],isprime[]= {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},vis[21];

//The code you must submit
void dfs(int step)
{
    ...
}

//The following codes will become the rear of your program automatically.
int main()
{
    int count;
    count=0;
    while(scanf("%d",&n)!=EOF)
    {
        count++;
        ans[1]=1;
        memset(vis,0,sizeof(vis));
        printf("Case %d:\n",count);
        dfs(2);
        printf("\n");
    }
    return 0;
}

示例输入:

6
8

示例输出:

Case 1:
1 4 3 2 5 6
1 6 5 2 3 4

Case 2:
1 2 3 8 5 6 7 4
1 2 5 8 3 4 7 6
1 4 7 6 5 8 3 2
1 6 7 4 3 8 5 2

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论