UVA-Prime Ring Problem

本文介绍了一道算法题目,要求在环形排列中填入自然数,使得任意相邻两数之和为素数。文章提供了完整的C++代码实现,采用深度优先搜索算法,并预先计算了指定范围内的所有素数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 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 ≤ 16)

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.
You are to write a program that completes above process.

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

题意:一个环有n个数字组成,这个环中相邻的两个数字的和为素数
方法:由题意可知,n的取值范围为[0,16],所以判断的素数的范围为[3,31],可以在程序开始处先求解出这个范围中的素数都有哪些,之后使用深度优先算法,判断是否相邻的两个数字的和为素数

#include <cstdio>
#include <memory.h>
#include <algorithm>

using namespace std;

bool is_prime[40];
int is_used[20];

void prime(){
    is_prime[2] = true;
    for(int i=3; i<40; i++){
        int j;
        for(j=2; j<i;j++){
            if(i%j == 0){
                is_prime[i] = false;
                break;
            }
        }
        if(j == i)
            is_prime[i] = true;
    }
}

void dfs(int *A, int n, int cur){
    if(cur == n && is_prime[A[0] + A[n-1]]){
        for(int i = 0; i < n-1; i++)
            printf("%d ", A[i]);
        printf("%d\n", A[n-1]);
    }
    else{
        for(int i = 2; i <= n; i++){
            if(!is_used[i] && is_prime[i + A[cur-1]]){
                A[cur] = i;
                is_used[i] = 1;
                dfs(A, n, cur+1);
                is_used[i] = 0;
            }
        }
    }
}

int main()
{
    int n;
    int cnt = 0;
    prime();
    while(~scanf("%d", &n)){
        if(cnt != 0)
            printf("\n");
        printf("Case %d:\n", ++cnt);
        int A[20];
        A[0] = 1;
        memset(is_used, 0, sizeof(int));
        dfs(A, n, 1);
    }
    return 0;
}
### 腾讯iOA私有化部署成本分析 腾讯iOA作为国内领先的零信任安全解决方案之一,支持SaaS、私有化及混合部署模式。在企业对数据安全性要求较高的场景下,私有化部署成为首选方案。以下从硬件投入、软件授权、运维服务等方面进行综合成本分析。 #### 硬件投入成本 私有化部署需要本地服务器资源来承载控制中心、网关和终端管理模块。根据典型中型企业需求,建议采用双节点高可用架构,每台服务器配置不低于8核CPU、32GB内存、1TB SSD存储空间,以保障策略计算、身份认证与访问控制的稳定运行[^2]。若采用物理服务器采购方式,两台设备成本约在10~15万元区间;若已有虚拟化平台,则可通过分配资源池降低硬件支[^1]。 #### 软件授权与服务费用 腾讯iOA私有化版本按用户数或终端数量进行授权计费,具体价格因功能模块组合而异。基础版包含零信任SDP(软件定义边界)与CWPP(云工作负载保护平台)能力,适用于远程办公与应用访问控制场景,年费约为每位用户300元起[^2]。对于500人规模的企业,年度授权成本约15万元。此外,首次部署需支付一次性实施服务费,涵盖系统集成、策略配置与接口对接等,通常为5~8万元[^3]。 #### 运维与扩展成本 私有化部署后需配备专业IT团队负责日常维护、日志审计与策略优化。若企业内部缺乏相应技术储备,可选择厂商提供的年度运维服务包,费用约为软件授权金额的20%~30%。随着业务增长,新增用户或功能模块扩展将产生额外成本,例如增加DLP(数据防泄漏)模块后,整体预算需上浮10%~15%。 #### 总体预算估算 综合上述因素,一个中型企业在完成腾讯iOA私有化部署后的首年总成本包括: - 硬件投入:10~15万元 - 软件授权:15万元(500用户规模) - 实施服务费:5~8万元 - 年度运维服务费:3~5万元 总计约33~41万元,略超30万元预算上限。若希望压缩至30万元以内,可通过精简功能模块(如仅启用SDP与基础身份认证)、复用现有服务器资源或延长付款周期等方式实现初步部署[^3]。 ```python # 成本估算示例代码 def estimate_cost(users=500, license_per_user=300, setup_fee=60000, maintenance_rate=0.25): hardware_cost = 120000 # 假设复用部分资源,取中间值 license_cost = users * license_per_user total_initial_cost = hardware_cost + license_cost + setup_fee annual_maintenance = (license_cost + setup_fee) * maintenance_rate total_first_year = total_initial_cost + annual_maintenance return { "Initial Hardware Cost": hardware_cost, "License Cost": license_cost, "Setup Service Fee": setup_fee, "Annual Maintenance": annual_maintenance, "Total First Year": total_first_year } estimate_cost() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值