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

 

Inputn (0 < n < 20). 
OutputThe 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

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<cstring>
 4 #include<queue>
 5 
 6 using namespace std;
 7 
 8 
 9 int n;
10 int a[23];
11 int vis[23];
12 bool mark[1000];
13 
14 void init()        // 素数筛 
15 {
16     for(int i = 2; i < 1000; ++i)
17         mark[i] = true;
18     
19     for(int i = 2; i < 1000; ++i)
20     {
21         if(mark[i] == true)
22         {
23             for(int j = i*i; j < 1000; j += i)
24             {
25                 mark[j] = false;
26             }
27         }
28     }
29 }
30 
31 // 边枚举边判断,不要最后一次性判断,会超时 
32 void dfs(int step)
33 {
34     if(step > 2)
35     {
36         if(mark[a[step-1]+a[step-2]] == false)    // 判断最后两个数 
37             return;
38     }
39     
40     if(step == n+1)
41     {
42         if(mark[a[n]+a[1]] == false)    // 判断最后一个数与第一个数 
43             return;
44         for(int i = 1; i < n; ++i)
45             printf("%d ", a[i]);
46         printf("%d\n", a[n]);
47 
48     }
49             
50     for(int i = 2; i <= n; ++i)
51     {
52         if(!vis[i])
53         {
54             a[step] = i;
55             vis[i] = 1;
56             dfs(step+1);
57             vis[i] = 0;
58         }
59         
60     }
61 }
62 
63 
64 int main()
65 {
66      init();
67      int cas = 1;
68      a[1] = 1;
69      while(scanf("%d", &n) != EOF)
70      {
71          printf("Case %d:\n", cas++);
72          memset(vis, 0, sizeof(vis));
73          dfs(2);
74          printf("\n");
75      }
76     
77     
78     return 0;
79 }

 

转载于:https://www.cnblogs.com/FengZeng666/p/11517509.html

内容概要:本文档主要介绍了Intel Edge Peak (EP) 解决方案,涵盖从零到边缘高峰的软件配置和服务管理。EP解决方案旨在简化客户的入门门槛,提供一系列工具和服务,包括Edge Software Provisioner (ESP),用于构建和缓存操作系统镜像和软件栈;Device Management System (DMS),用于远程集群或本地集群管理;以及Autonomous Clustering for the Edge (ACE),用于自动化边缘集群的创建和管理。文档详细描述了从软件发布、设备制造、运输、安装到最终设备激活的全过程,并强调了在不同应用场景(如公共设施、工业厂房、海上油井和移动医院)下的具体部署步骤和技术细节。此外,文档还探讨了安全设备注册(FDO)、集群管理、密钥轮换和备份等关键操作。 适合人群:具备一定IT基础设施和边缘计算基础知识的技术人员,特别是负责边缘设备部署和管理的系统集成商和运维人员。 使用场景及目标:①帮助系统集成商和客户简化边缘设备的初始配置和后续管理;②确保设备在不同网络环境下的安全启动和注册;③支持大规模边缘设备的自动化集群管理和应用程序编排;④提供详细的密钥管理和集群维护指南,确保系统的长期稳定运行。 其他说明:本文档是详细描述了Edge Peak技术及其应用案例。文档不仅提供了技术实现的指导,还涵盖了策略配置、安全性和扩展性的考虑,帮助用户全面理解和实施Intel的边缘计算解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值