HDU 1016Prime Ring Problem
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的更多相关文章
- 1016-Prime Ring Problem,素数环,深搜!
Prime Ring Problem ...
- hdu Prime Ring Problem
简单的dfs,貌似这道题用暴力枚举就可以了,毕竟数据开的是比较小的. #include"iostream" #include"algorithm" #inclu ...
- HDU 1016 Prime Ring Problem(经典DFS+回溯)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- [HDU 1016]--Prime Ring Problem(回溯)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- HDU 1016 Prime Ring Problem(素数环问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- HDOJ(HDU).1016 Prime Ring Problem (DFS)
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- 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 ...
- hdu 1016 Prime Ring Problem(DFS)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1016 Prime Ring Problem(深度优先搜索)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- 【转】tomcat7性能调优
注意:调优tomcat需要了解使用的tomcat是什么版本,随着tomcat版本发展有新参数引入,同时有旧参数废弃.本文档以tomcat7为例进行调优 一. 线程池(Thread Pool)优化 编辑 ...
- jquery mobile 输入框无边框
现在移动开发为主流的时代,少不了使用jquery mobile.但是偶然应项目要求需要把input输入框做成无边框的,不是特别容易的事,网上找了很多都没有一种靠谱的解决方案,只能自食其力了. < ...
- Python开发入门与实战16-APACHE部署
16. Windows平台apache部署 本章节我们简要的描述一下如何在windows平台部署apache的django站点. Python Django 项目部署发布到windows apache ...
- css 中content内容特殊形状
用到的一些特殊字符和图标html代码<div class="cross"></div>css代码.cross{ width: 20px; hei ...
- php 序列化、json
序列化 和 反序列化1. serialize和unserialize函数 2. json_encode 和 json_decode 使用JSON格式序列化和反序列化3. var_export 和 ev ...
- Spearman秩相关系数和Pearson皮尔森相关系数
1.Pearson皮尔森相关系数 皮尔森相关系数也叫皮尔森积差相关系数,用来反映两个变量之间相似程度的统计量.或者说用来表示两个向量的相似度. 皮尔森相关系数计算公式如下:
- Hive的API的说明
之前通过命令行的界面可以操作Hive,可是在实际的生产环境中,往往都是需要写API的,因此对Hive的API简单的列举了一下.并对Hive进行了一个简单的封装.具体的封装可以参考github网站主页: ...
- 《C++primer》v5 第8章 IO库 读书笔记 习题答案
8.1.8.2 这一章不咋会啊.. istream &read(istream &is) { int a; auto old_state=is.rdstate(); is.clear( ...
- std::vector<bool>中的坑
http://www.cplusplus.com/reference/vector/vector/?kw=vector C++中,vector<bool>为了达到节省内存的目的,专门做了特 ...
- MyBatis 配置文件头部换行异常
INFO - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory ...