Prime Ring Problem(HDU-1016)

医疗设备安规入门:一张图搞懂BF型设备的MOOP/MOPP绝缘路径(附GB 9706.1附录解析) 本文深入解析了BF型医疗设备的MOOP/MOPP绝缘路径设计,结合GB 9706.1标准附录J的实战应用,帮助工程师快速掌握医疗设备安规要点。通过典型绝缘路径图分析,详细对比了MOOP与MOPP的防护差异,并提供了海拔修正、漏电流测试等关键设计指南,助力医疗设备安全合规。 阅读详情
Problem Description
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.


 

Input
n (0 < n < 20).
 

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. 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
 
代码如下:
#include<bits/stdc++.h>
using namespace std;
int prime[50]={0,0},r[50]={1},n,vis[50]={0};
void dfs(int k)
{
    if(k==n-1&&prime[r[k]+r[0]])
    {
        for(int i=0;i<n-1;i++)
            cout<<r[i]<<" ";
        cout<<r[n-1]<<endl;
    }
    for(int i=2;i<=n;i++)
        if(!vis[i]&&prime[i+r[k]])
        {
            vis[i]=1;
            r[k+1]=i;
            dfs(k+1);
            vis[i]=0;
        }
}
int main()
{
    int t=1;
    for(int i=2;i<=40;i++)
    {
        prime[i]=1;
        for(int j=2;j*j<=i;j++)
            if(i%j==0)
            {
                prime[i]=0;
                break;
            }
    }
    while(cin>>n)
    {
        cout<<"Case "<<t<<":\n";
        dfs(0);
        cout<<endl;
        t++;
    }
    return 0;
}



Ubuntu零基础教学-如何把Ubuntu20.04界面从英文修改为中文?| 超级详细,建议收藏 带你如何把Ubuntu20.04界面从英文修改为中文?| 超级详细,建议收藏 阅读详情

相关推荐

HMC7044芯片模拟SPI配置

摘要: HMC7044是一款高性能双环路整数N分频抖动衰减器,支持SPI接口配置,适用于高速数据转换器时钟系统。该芯片采用双PLL级联架构,具有14路可配置输出,可满足GSM/LTE基站设计需求。SPI接口采用3线模式(SLEN/SCLK/SDATA),支持24位寄存器读写(13位地址+8位数据)。驱动实现基于Zynq EMIO模拟SPI,提供初始化、数据传输及寄存器配置功能,支持三线制工作模式和多种时钟参数设置。

toonyhe的博客 1099

HDU1016--素数环问题

HDU1016–素数环问题 目录HDU1016--素数环问题一、题目链接二、题目内容三、题意拆解四、解题思路五、参考代码 一、题目链接 HDU1016 二、题目内容 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 pr

Verber的博客 1386

获取本机正版windows10激活密钥,以及正版office

本方法面向的是以前买过笔记本电脑给你预装了正版系统,激活了正版office(一般是家庭版)的情况,其他情况请自行尝试。

qq_45774917的博客 2万+

总理戒指(素数圆环)

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. Input n (0 < n < 20

lymww的博客 590

从流体力学到深度学习:手把手教你用PINN预测涡流场(基于TensorFlow2.10+GPU)

本文详细介绍了如何利用物理信息神经网络(PINN)结合TensorFlow 2.10和GPU加速,预测Navier-Stokes方程的涡流场。通过核心原理讲解、实战环境配置、网络架构设计及物理约束实现,帮助读者掌握从流体力学到深度学习的跨学科技术应用,特别适合处理复杂流体问题和非定常流动场景。

weixin_29048309的博客 215

通过监督微调(SFT)提升AI Agent效果的完整指南

监督微调(Supervised Fine-Tuning)是在大规模预训练语言模型(如LLaMA、GPT系列)的基础上,使用特定任务标注数据进行二次训练的过程。其本质是通过有监督学习调整模型参数,使其适应目标任务的分布特征。

保持热爱。 1924

翻译(18)

题目:Prime Ring Problem | JXNUOJ 描述: 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

Ling_1501的博客 7574

手把手教你用ROS2控制PX4无人机画个圆:从C++代码到Gazebo仿真全流程解析

本文详细解析了如何使用ROS2控制PX4无人机实现圆形轨迹飞行,涵盖从C++代码编写到Gazebo仿真的全流程。重点介绍了Offboard模式下的控制算法实现、圆形轨迹生成的数学原理,以及解决通信延迟和坐标系转换等常见问题的实用技巧。通过实战案例,帮助开发者快速掌握无人机轨迹跟踪仿真的核心技术。

weixin_30839881的博客 99

每日一题(二十八):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...

老肥码码码 335

UG/NX二次开发实战:用Python脚本批量更新100个零件参数,解放你的双手

本文详细介绍了如何利用NXOpen Python API进行UG/NX二次开发,实现批量更新100个零件参数的自动化流程。通过环境配置、框架设计、核心代码实现及性能优化,帮助工程师高效完成参数化设计任务,显著提升工作效率。

weixin_28694169的博客 277

Sentence-BERT 语义相似度双塔模型

论文介绍 发表:2019,EMNLP 论文题目:《Sentence-BERT:sentence embeddings using siaese BERT-networks》 论文地址:https://arxiv.org/abs/1908.10084 Github:https://github.com/UKPLab/sentence-transformers 适用领域: 句向量生成 语义相似度计算 语义搜索 无监督任务(聚类) 1 概述 在20年之前的各种预训练模型中,比如bert,XLNet,Alb

weiyaner的博客 9195

【ACM- OJ】《prime circle》C++

【ACM- OJ】《prime circle》C++题目描述输入输出样例输入样例输出AC代码 题目描述 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 c

HISS的博客 1028

芯片工程师-必须掌握的linux操作-第一讲

一个从材料专业,转行芯片验证初级工程师,自己也是从0基础开始学习入门,更知道0基础的人应该怎么去学习。 现在工作三个多月了,特地花时间给大家写这篇文章。希望能关注、支持下。 为什么芯片验证工程师必须要学习linux命令? 答: ① 芯片工程师主要的职责,就是与IC设计工程师和系统工程师密切合作,开发验证平台,能够根据项目要求产生测试计划,产生代码及功能覆盖率,撰写验证报告。 ②简单点说,主要工作内容,是编写代码去验证设计的对不对。 那么问题来了,编写代码,在什么环境呢,我现在告诉你,都是在linux系统中进

小白蒋-材料转行芯片验证 4844

hdu 1016 Prime Ring Problem

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description A ring is compose of n ci...

qq_45852004的博客 152

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

深搜经典题型 hdu1016 Prime Ring Problem

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K Problem Description A ring is compose of n circles as ...

weixin_43732535的博客 233

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

hdu1016 Prime Ring Problem

hdu1016 Prime Ring Problem ...................... 1 #include <iostream> 2 #include <string.h> 3 #include <string> 4 #include <queue> 5 #i...

weixin_30820151的博客 95

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

HDOJ 1016 HDU 1016 Prime Ring Problem ACM 1016 IN HDU

题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1016题目描述:Prime Ring ProblemTime Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6150Accepted...

weixin_30483697的博客 136

HDU-1016 Prime Ring Problem(深搜)

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

碳酸钙的01妖精的博客 209

HDU 1016 Prime Ring Problem

HDU 1016 Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 27785    Accepted Submission(s): 12345 Problem Description A ri

Spectacules的博客 429

hdu1016Prime Ring Problem

http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11874    Accepted Submissi

hnust_xiehonghao的专栏 721

【HDU 1016】Prime Ring Problem(DFS、素数筛)

思路: 要求每两个相邻数之和都为素数,那么只要每次递归调用DFS时判断之前两个数之和是否为素数,另外注意因为是一个环,最后还要判断一下最后一个数和第一个数之和是否为素数。 程序开始时求出一个素数数组,只需求出50以内的素数即可,因为数据<20,最大的素数和为17+19=36。此处用的是素数筛法(什么是素数筛法?)求素数。 素数筛法概览: 把从1开始的、某一范围内的正整数从小到大顺序排列, 1不是素数,首先把它筛掉

Chen_yuazzy的博客 2261

hdu 1016 Prime Ring Problem

hdu  1016  Prime Ring Problem             题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 DFS 题目大意:输入一个数,将自然数1~此数排成一个圈,使每两个相邻的数相加之和为素数。 题目分析:标准DFS。 code; #include #include int p[40],vis[20],r

slicer的技术交流栈 709

Prime Ring Problem HDU - 1016

素数环 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; int n; int a[30]; int v[30]; bool prime( int x ){ for( int i = 2 ; i <= sqrt(x) ; i++ ) if( x % i =

qq_43627860的博客 131
上一篇: N皇后问题(HDU-2553)
下一篇: 逃离迷宫(HDU-1728)
绿蚁.r
博客等级 码龄10年 4粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值