`
isiqi
  • 浏览: 16002980 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

HDUOJ1016 Prime Ring Problem

阅读更多

Prime Ring Problem

Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8087Accepted Submission(s): 3620

Problem Description
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.

Input
n (0 < n < 20).
Output
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.
Sample Input
6 8
Sample Output
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
【解题思路】素数环是典型的DFS题目,DFS函数的参数为(int c, int cnt),
c代表遍历时所在环上节点的数,cnt代表结点个数。当节点个数位n时并且环末节点
和首节点相加也为素数则打印环。

根据本题总结dfs的主要步骤和方法:

1. 找搜索出口条件,即搜索到最深层时的操作

2. Dfs采用递归搜索,在遍历后返回时标记已经遍历的节点

3. 注意入口条件的满足

4. 画出递归搜索图查看函数是否满足要求

5. 注意回溯的条件,适当的时候需要剪枝

分享到:
评论

相关推荐

    Prime Ring Problem 深度探索

    深度探索 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

    E-Prime程序示例.zip

    E-Prime示例集E-Prime示例集E-Prime示例集E-Prime示例集E-Prime示例集E-Prime是由卡奈基-梅龙大学和匹兹堡大学联合开发心理学实验操作平台,是一个高等的图形设计环境,提供革命性的新工具,以加速实验发展,E-Prime...

    prime 算法 prime

    prime 算法 prime prime prime

    eprime真正破解版1.1

    心理学实验eprime

    LynX_Prime_Interface.rar_lynx prime_lynx vega_vega_vega prime_ve

    vega prime 使用模块说明vega prime 使用模块说明vega prime 使用模块说明

    vega prime安装步骤

    用于vega prime的安装,可以使读者能够准确并且轻松地完成安装

    prime95使用教程.pdf

    prime95使用教程.pdfprime95使用教程.pdfprime95使用教程.pdfprime95使用教程.pdfprime95使用教程.pdfprime95使用教程.pdf

    E-Prime音频控件使用简单测试

    用于E-Prime的初学者解决一些音频控件相关的简单设置问题,是E-Prime 2.0版本软件创建的一个非常简单的项目示例。

    E-prime真正破解版

    用于心理实验的E-prime程序,希望帮助到大家。

    IAT实验E-PRIME报告.doc

    IAT实验E-PRIME报告

    primesense Sensor-Win64-5.1.6.6

    primesense Sensor-Win64-5.1.6.6,用于windows系统32位primesense sensor的驱动

    心理学eprime制作flanker实验

    心理学eprime制作flanker实验

    HP Prime 绘图计算器

    HP prime 计算器的手册。 HP Prime 绘图计算器是一款易于使用且功能强大的绘图计算器,它是专为中学及高等数学教育而设计 的。它提供了数百个函数和命令,并且包含一个用于符号计算的计算机代数系统 (CAS)。 除了...

    E-Prime软件+安装方法+教程

    E-Prime软件+安装方法+教程 毕设的时候用的,总结上传上来,完全可以使用。

    E-prime实验设计技术(曾祥炎)

    E-prime实验设计技术

    Quartus Prime 18.1 破解器

    Quartus Prime 18.1 破解器 # 第一步: 把Quartus_18.1破解器.exe复制到C:\intelFPGA\18.1\quartus\bin64和/或C:\intelFPGA_Pro\18.1\quartus\bin64下运行(你的安装目录也许和这个不一样),也就是说把它和quartus....

    Prime OS_mainline_v0.4.5.iso

    Android x86 系列的操作系统,在PC上运行的安卓, 非虚拟机模拟。 PrimeOS_Mainline_v0.4.5 , ISO 安装盘映像文件。网盘下载链接。

    Prime95v258.zip

    rime95是一款专门测试系统稳定的软件,在所有的拷机软件中,Prime95是公认的最残酷的一款。它把负荷高得有点离谱的工作量加载在CPU身上,以此来考验CPU的承受能力。这一测试因其可以发现其他测试程序无法发现的稳定...

    Prime95中文版

    Prime95是一款专门测试系统稳定的软件,在所有的烤机软件中,Prime95 是公认的最残酷的一款.它把负荷高得有点离谱的工作量加载在CPU身 上,以此来考验CPU的承受能力.这一测试因其可以发现其他测试程序无法发现的稳定性...

    PrimeOS_Mainline_v0.4.5_Windows x64 安装包

    Android x86 系列的操作系统,在PC上运行的安卓, 非虚拟机模拟。 PrimeOS_Mainline_v0.4.5 , Windows x64 安装包。网盘下载链接。

Global site tag (gtag.js) - Google Analytics