http://acm.hdu.edu.cn/showproblem.php?pid=1016

题意:输入一个数,给出符合要求的素数环。

经典的dfs遍历。

 #include<iostream>
#include<cstring>
#include<cmath>
using namespace std; int visited[];
int pos[];
int n, kase = ; int judge(int x) //判断是否为素数
{
for (int i = ; i <= sqrt(x); i++)
{
if (x%i == ) return ;
}
return ;
} void dfs(int x,int count)
{
pos[count] = x;
visited[x] = ;
if (count == n && judge(x + pos[]))
{
for (int i = ; i < n; i++)
cout << pos[i] << " ";
cout << pos[n];
cout << endl;
}
for (int k = ; k <= n; k++)
{
if (!visited[k] && judge(k+pos[count]))
{
dfs(k, count+);
visited[k] = ;
}
}
} int main()
{
while (cin >> n && n)
{
memset(visited, , sizeof(visited));
memset(pos, , sizeof(pos));
kase++;
cout << "Case " << kase << ":" << endl;
dfs(,);
cout << endl;
}
return ;
}

HDU 1016Prime Ring Problem的更多相关文章

  1. 1016-Prime Ring Problem,素数环,深搜!

    Prime Ring Problem                                                                                   ...

  2. hdu Prime Ring Problem

    简单的dfs,貌似这道题用暴力枚举就可以了,毕竟数据开的是比较小的. #include"iostream" #include"algorithm" #inclu ...

  3. HDU 1016 Prime Ring Problem(经典DFS+回溯)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. [HDU 1016]--Prime Ring Problem(回溯)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...

  5. HDU 1016 Prime Ring Problem(素数环问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...

  6. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  7. Prime Ring Problem HDU - 1016 (dfs)

    Prime Ring Problem HDU - 1016 A ring is compose of n circles as shown in diagram. Put natural number ...

  8. hdu 1016 Prime Ring Problem(DFS)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. hdu 1016 Prime Ring Problem(深度优先搜索)

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

随机推荐

  1. nginx 高并发配置参数(转载)

    声明:原文章来自http://blog.csdn.net/oonets334/article/details/7528558.如需知道更详细内容请访问. 一.一般来说nginx 配置文件中对优化比较有 ...

  2. C# unity3d 贪吃蛇 游戏 源码 及其感想

    这个游戏的设计过程是这样的: 1,创建

  3. ng-Enter指令

    app.directive('ngEnter', function() { return function(scope, element, attrs) { element.bind("ke ...

  4. tail 显示文件最后若干行内容

    功能:tail命令可以输出文件的尾部内容,默认情况下它显示文件的最后十行.显示每个指定文件的最后10 行到标准输出.若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头.如果不指定文件或文 ...

  5. VMware下利用ubuntu13.04建立嵌入式开发环境之一

    1.软件准备: (1) VMware网上很多,需要根据自己的需要选择,这里选用的VMware Workstation 9. (2)ubuntu  操作系统,同样根据自己的需要下载系统安装包.这里我选择 ...

  6. linux 常用操作指令(随时更新)

    ls: 查看当前目录下文件列表 -l   列出文件详细信息l(list)  -a   列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir         创建目录 -p         ...

  7. 【python】闭包、@修饰符(装饰器)、

    闭包:(返回函数的行为叫闭包??) #函数也是对象,所以可以被传递 def line_conf(a,b): def line(x): return a*x+b return line line1=li ...

  8. OpenSSL 使用拾遗(一)---- 生成 pkcs12 文件

    从本期开始,记录一些在使用 OpenSSL 过程中碰到的问题及解决办法 在 Linux 下需要生成 pkcs12 文件,立即想到 OpenSSL.键入如下命令 ~ # openssl pkcs12 - ...

  9. ORB

    http://wenku.baidu.com/link?url=R4Ev8aJNxwmjV0egSUqVBjmnt1KT_llzp8Oy2NbHnwa7Me9UAIHkiMG2Vwucu3RSDKwy ...

  10. Codeforces

    Codeforces 7E #include <iostream> #include <cstring> #include <cstdio> #include &l ...