素数环 Primg Ring Problem】的更多相关文章

素数环 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/C 题意: 输入正整数n,把整数1~n组成一个环,使相邻的两个整数之和均为素数.输出时从整数1开始逆时针排列. 同一个环应恰好输出一次.n<=16 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…
题目OJ地址: https://www.luogu.org/problemnew/show/UVA524 hdu oj 1016:  https://vjudge.net/problem/HDU-1016 zoj 1457  :https://vjudge.net/problem/ZOJ-1457 题意翻译 输入正整数n,把整数1,2,...,n组成一个环,使得相邻两个整数之和均为素数.输出时,从整数1开始逆时针排列.同一个环恰好输出一次.. 多组数据,读入到EOF结束. 第i组数据输出前加上一…
标签:搜索与回溯 题目: 从1到20这20个数摆成一个环,要求相邻的两个数的和是一个素数. 算法分析: 非常明显,这是一道回溯的题目.从1开始,每个空位有20种可能,只要填进去的数合法:与前面的数不相同:与左边相邻的数的和是一个素数.第20个数还要判断和第1个数的和是否素数. 算法流程: 1.数据初始化: 2.递归填数:判断第i个数填入是否合法: A.如果合法:填数:判断是否到达目标(20个已填完):是,打印结果:不是,递归填下一个: B.如果不合法:选择下一种可能: 题解: #include…
Prime Ring Problem 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.…
/* Name: NYOJ--488--素数环 Author: shen_渊 Date: 15/04/17 15:30 Description: DFS,素数打个表,37以内就够用了 */ #include<cstring> #include<iostream> #include<cstdio> #include<algorithm> using namespace std; void dfs(int); int n; //int prime[25] = {…
Prime Ring Problem                                                                                                                Time Limit: 4000/2000 MS (Java/Others)                                                                                  …
Prime Ring Problem 思路:先看成一条链,往里头填数,满足任意相邻两数和为质数(这可以打表预处理出40以内的所有质数,扩展的时候枚举),填完了后检查首尾是否满足条件.字典序可以采用扩展时从小到大枚举.另外注意对于每个case多输出一个换行,行末不要有空格. #include<bits/stdc++.h> using namespace std; int n,cnt,a[25]; bool p[45],vis[25]; void print() { for(int i=1;i&l…
  Prime Ring Problem  A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 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…
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18313    Accepted Submission(s): 8197 Problem Description A ring is compose of n circles as shown in diagram. Put natural numbe…
Prime Ring Problem Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 18   Accepted Submission(s) : 7 Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2,…