DFS__1195: Prime Ring Problem

这道题目搞得我老郁闷了,首先是DFS的构造,是通过2数之和来DFS的.接着的话对于边界条件1,是不输出的,而这个我是没考虑到的,1是不输出的!!!!!!!!!!!!!!!!!!!!!!!!!!!!!接着通过奇偶数分析可以更快


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout10s8192K1339393Standard

A ring is composed of n 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 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

 


This problem is used for contest: 102 


Submit / Problem List / Status / Discuss

#include<iostream>     //冲刺。AIBERT
#define MAXN 41
bool p[MAXN],visit[17];//P是用来记录MAXN内的素数,VISIT是用来记录1~N里面的数字是否被使用
int circle[17],n;  //用来储存每位上的数字
void prime()
{
     memset(p,true,sizeof(p)); //全部初始化为TRUE  
     p[1]=false;
     for(int i=2;i<=16;i++)
       for(int j=2;i*j<=MAXN;j++) 
         p[i*j]=false;  
}
void dfs(int c,int depth)
{
     if(depth==n && p[circle[1]+circle[n]] )   //如果到了第N层并且满足第N个和第一个的和为质数
       {
                 for(int i=1;i<=n-1;i++)
                    printf("%d ",circle[i]);
                 printf("%d/n",circle[n]);
       }
     for(int i=c+2;i<=MAXN;i++)             //I为两个数字之和,是在C+2和MAXN之间 ,因为1已经被使用
       if(i-c<=n && p[i] && visit[i-c])//I-C在N范围内,P[I]表示两数之和为质,并且数字未被使用
        {
            circle[depth+1]=i-c;
            visit[i-c]=false;
            dfs(i-c,depth+1);
            visit[i-c]=true;
        }
}                           
int main()
{
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    int count=1;
    prime();
    while(scanf("%d",&n)!=EOF)
    {                                          
       printf("Case %d:/n",count++);      //COUNT是用来记录CASE的序号 
       if(n!=1&&n%2!=1)
       {
       memset(visit,true,sizeof(visit));    //初始化VISIT数组全为TRUE
       visit[1]=false;circle[1]=1;         //第一个点为1,则VISIT[1]为FALSE,第一个点为一
       dfs(1,1);   //前面的一表示前面这个结点植为1,在第一层
       }
       printf("/n");
    }
    return 0;
}    

uint32_t hmac_zero_dfs_ont_acs_set_channel_handle(mac_vap_stru *mac_vap, uint8_t chan_num, uint8_t bandwidth, uint32_t switch_mode) { hmac_zero_dfs_mode_enum zero_dfs_mode; mac_channel_stru new_channel = { 0 }; uint32_t ret; if (OAL_UNLIKELY(mac_vap == NULL)) { OAM_ERROR_LOG0(0, OAM_SF_ZERO_DFS, "hmac_zero_dfs_ont_acs_set_channel_handle: invalid input param"); return OAL_ERR_CODE_PTR_NULL; } zero_dfs_mode = hmac_zero_dfs_get_mode(mac_vap); if (zero_dfs_mode == ZERO_DFS_CLOSE) { OAM_M_WARNING_LOG0(mac_vap->uc_chip_id, mac_vap->uc_vap_id, OAM_SF_MLOG, "hmac_zero_dfs_ont_acs_set_channel_handle: zero dfs is closed"); return OAL_FAIL; } memcpy_s(&new_channel, sizeof(mac_channel_stru), &mac_vap->st_channel, sizeof(mac_channel_stru)); new_channel.en_bandwidth = bandwidth; new_channel.uc_chan_number = chan_num; ret = mac_get_channel_idx_from_num(mac_vap->st_channel.en_band, chan_num, &new_channel.uc_chan_idx); if (OAL_UNLIKELY(ret != OAL_SUCC || bandwidth >= WLAN_BAND_WIDTH_BUTT)) { OAM_M_ERROR_LOG2(mac_vap->uc_chip_id, mac_vap->uc_vap_id, OAM_SF_MLOG, "hmac_zero_dfs_ont_acs_set_channel_handle: invalid chan_num[%u] or bandwidth[%u]", chan_num, bandwidth); return OAL_ERR_CODE_INVALID_CONFIG; } if (switch_mode == HW_ACS_SWITCH_DONE_PRECAC && zero_dfs_mode == ZERO_DFS_PRE_CAC) { if (hmac_dfs_need_for_cac(mac_vap, &new_channel) == OAL_TRUE) { OAM_M_ERROR_LOG1(mac_vap->uc_chip_id, mac_vap->uc_vap_id, OAM_SF_MLOG, "hmac_zero_dfs_ont_acs_set_channel_handle: unable to switch to radar channel[%u]", chan_num); return OAL_FAIL; } return hmac_zero_dfs_switch_channel(mac_vap, chan_num, bandwidth, CHAN_ZERO_DIRECT); } else if (switch_mode == HW_ACS_SWITCH_ZERO_CAC && zero_dfs_mode != ZERO_DFS_PRE_CAC) { if (hmac_zero_dfs_need_cac(mac_vap, &new_channel) == OAL_FALSE) { OAM_M_WARNING_LOG0(mac_vap->uc_chip_id, mac_vap->uc_vap_id, OAM_SF_MLOG, "hmac_zero_dfs_ont_acs_set_channel_handle: don't need zero cac"); return OAL_FAIL; } hmac_zero_dfs_record_channel(mac_vap, &new_channel, OAL_TRUE); return hmac_zero_dfs_try_cac(mac_vap, &new_channel, SCAN_FLAG_TARGET, 0); } else { OAM_M_WARNING_LOG2(mac_vap->uc_chip_id, mac_vap->uc_vap_id, OAM_SF_MLOG, "hmac_zero_dfs_ont_acs_set_channel_handle: invalid switch_mode[%u] for zero_dfs_mode[%u]", switch_mode, zero_dfs_mode); return OAL_FAIL; } } #endif oal_bool_enum_uint8 hmac_dfs_need_for_cac(const mac_vap_stru *mac_vap, const mac_channel_stru *channel) { hmac_band_stru *hmac_band = NULL; #ifdef _PRE_WLAN_FEATURE_MULTIAP uint8_t ret; #endif if (OAL_IS_NULL_PTR2(mac_vap, channel)) { OAM_ERROR_LOG0(0, OAM_SF_DFS, "hmac_dfs_need_for_cac::input param is NULL"); return OAL_ERR_CODE_PTR_NULL; } hmac_band = hmac_band_get_by_vap_id(mac_vap->uc_chip_id, mac_vap->uc_vap_id); if (OAL_IS_NULL_PTR1(hmac_band)) { OAM_ERROR_LOG0(0, OAM_SF_DFS, "hmac_dfs_need_for_cac::hmac_band is NULL"); return OAL_ERR_CODE_PTR_NULL; } /* dfs使能位 */ if (hmac_vap_get_dfs_enable(mac_vap) == OAL_FALSE) { OAM_WARNING_LOG0(0, OAM_SF_DFS, "hmac_dfs_need_for_cac::dfs not enable"); return OAL_FALSE; } /* CAC使能位 */ if (mac_dfs_get_cac_enable(&(hmac_band->st_feature.st_dfs_info)) == OAL_FALSE) { OAM_WARNING_LOG0(0, OAM_SF_DFS, "hmac_dfs_need_for_cac::cac not enabled"); return OAL_FALSE; } /* 定时器使能位 */ if (hmac_band->st_feature.st_dfs.st_dfs_cac_timer.en_is_enabled == OAL_TRUE) { /* 如果已经开始CAC检测,原则上可以不再重启定时器,此处可以返回false */ OAM_WARNING_LOG0(0, OAM_SF_DFS, "hmac_dfs_need_for_cac::dfs tiemer enabled, need restart"); } if (channel->en_band != WLAN_BAND_5G) { OAM_WARNING_LOG0(0, OAM_SF_DFS, "hmac_dfs_need_for_cac::dfs no need on 2G channel"); return OAL_FALSE; } #ifdef _PRE_WLAN_FEATURE_6G_EXTEND if (IS_6G_BAND_VAP(mac_vap) != OAL_FALSE) { OAM_WARNING_LOG0(0, OAM_SF_DFS, "hmac_dfs_need_for_cac::dfs no need on 6G channel"); return OAL_FALSE; } #endif /* 检查子信道状态 */ if (hmac_dfs_check_channel_need_cac(hmac_band, channel) == OAL_FALSE) { return OAL_FALSE; } #ifdef _PRE_WLAN_FEATURE_MULTIAP ret = hmac_multiap_check_ctrl_dfs_chn_clear_indication(hmac_band, channel->uc_chan_idx, channel->en_bandwidth); if (ret == OAL_TRUE) { return OAL_FALSE; } #endif return OAL_TRUE; } oal_bool_enum_uint8 hmac_zero_dfs_need_cac(const mac_vap_stru *mac_vap, const mac_channel_stru *channel) { const hmac_band_stru *hmac_band = NULL; mac_channel_stru radar_channel = { 0 }; if (OAL_IS_NULL_PTR2(mac_vap, channel)) { OAM_ERROR_LOG0(0, OAM_SF_ZERO_DFS, "hmac_zero_dfs_need_cac::input param is NULL"); return OAL_FALSE; } hmac_band = hmac_band_get_by_vap_id(mac_vap->uc_chip_id, mac_vap->uc_vap_id); if ((OAL_IS_NULL_PTR1(hmac_band))) { OAM_ERROR_LOG0(mac_vap->uc_vap_id, OAM_SF_ZERO_DFS, "hmac_zero_dfs_need_cac::hmac_band is NULL"); return OAL_FALSE; } /* 检查zero dfs特性是否使能 */ if (hmac_zero_dfs_get_mode(mac_vap) == ZERO_DFS_CLOSE) { OAM_WARNING_LOG0(mac_vap->uc_vap_id, OAM_SF_ZERO_DFS, "hmac_zero_dfs_need_cac: zero dfs is closed"); return OAL_FALSE; } /* 检查带宽内子信道是否需要做cac */ if (hmac_dfs_check_channel_need_cac(hmac_band, channel) == OAL_FALSE) { return OAL_FALSE; } hmac_zero_dfs_get_radar_covered_channel(channel, hmac_band, &radar_channel); if (radar_channel.en_bandwidth > get_wlan_zero_dfs_max_phy_bw(mac_vap->chip_type)) { OAM_WARNING_LOG0(mac_vap->uc_vap_id, OAM_SF_ZERO_DFS, "hmac_zero_dfs_need_cac::don't support over max bw cac"); return OAL_FALSE; } return OAL_TRUE; } typedef enum { HW_ACS_SWITCH_NO_PRECAC, /* 未检测preCAC,选择雷达信道需要静默CAC */ HW_ACS_SWITCH_DONE_PRECAC, /* 检测过preCAC,无论是否为雷达信道,直接切换 */ HW_ACS_SWITCH_ZERO_CAC, /* 未检测preCAC,选择雷达信道需要先做preCAC,未检测到雷达再切换信道 */ HW_ACS_SWITCH_BUTT } hw_acs_switch_mode; #ifdef _PRE_WLAN_FEATURE_ZERO_DFS typedef enum { ZERO_DFS_CLOSE, /* 特性关闭 */ ZERO_DFS_INIT_MUTE, /* 上电静默 */ ZERO_DFS_INIT_WORK, /* 上电工作 */ ZERO_DFS_PRE_CAC, /* preCAC直切 */ ZERO_DFS_MODE_BUTT } hmac_zero_dfs_mode_enum; 根据上面代码解释工作流程
最新发布
09-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值