南邮 OJ 1128 An Industrial Spy

本文介绍了一道编程竞赛题,题目要求从给定的数字中找出能组成的不同素数的数量。文章提供了完整的代码实现,包括素数筛法初始化、生成所有可能组合并检查是否为素数的过程。

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

An Industrial Spy

时间限制(普通/Java) :  10000 MS/ 30000 MS          运行内存限制 : 65536 KByte
总提交 : 38            测试通过 : 20 

比赛描述

Industrial spying is very common for modern research labs. I am such an industrial spy { don't tell anybody! My recent job was to steal the latest inventions from a famous math research lab. It was hard to obtain some of their results but I got their waste out of a document shredder.

I have already reconstructed that their research topic is fast factorization. But the remaining paper snippets only have single digits on it and I cannot imagine what they are for. Could it be that those digits form prime numbers? Please help me to nd out how many prime numbers can be formed using the given digits.




输入

The rst line of the input holds the number of test cases c (1 <= c <= 200). Each test case consists of a single line. This line contains the digits (at least one, at most seven) that are on the paper snippets.


输出

For each test case, print one line containing the number of di erent primes that can be reconstructed by shuing the digits. You may ignore digits while reconstructing the primes (e.g., if you get the digits 7 and 1, you can reconstruct three primes 7, 17, and 71). Reconstructed numbers that (regarded as strings) di er just by leading zeros, are considered identical (see the fourth case of the sample input).


样例输入

4
17
1276543
9999999
011

样例输出

3
1336
0
2

题目来源

NWERC2009




#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#define MAXN 10000000
char isp[MAXN], visp[MAXN], vis[MAXN];
int a[10], t[10], sum;
void init(){
	int i,j;
	isp[0]=isp[1]=1;
	isp[2]=isp[3]=0;
	for(i=4;i<MAXN;){
		isp[i++]=1;
		isp[i++]=0;			//最大i==N-1,为奇数,不会越界访问
	}
	int halfN = MAXN>>1,doubleI;
	for(i=3;i<=halfN;i+=2){
		if(!isp[i]){
			doubleI = i<<1;
			for(j=i*3;j<MAXN;j+=doubleI){
				isp[j]=1;
			}
		}
	}
}
int ToNum(int n){
    int sum = 0;
    for(int i = 0;i < n;i ++) sum = sum*10 + t[i];
    return sum;
}
void dfs(int n, int dep){
    if(dep == n){
        int tmp = ToNum(n);
        if(!isp[tmp] && !visp[tmp]){
            sum++;
            visp[tmp] = 1;
        }
        return;
    }
    for(int i = 0;i < n;i ++){
        if(!vis[i]){
            vis[i] = 1;
            t[dep] = a[i];
            dfs(n, dep+1);
            vis[i] = 0;
        }
    }
}
int main(){
    char str[10];
    int tt, b[10];
    init();
    scanf("%d", &tt);
    while(tt--){
        memset(str, 0, sizeof(str));
        scanf("%s", str);
        int len = strlen(str);
        for(int i = 0;i < len;i ++) b[i] = str[i]-'0';
        memset(visp, 0, sizeof(visp));
        int ans = 0;
        int UP = (1 << len);
        for(int i = 1;i < UP;i ++){
            int k = 0;
            for(int j = 0;j < len;j ++)
                if(i & (1 << j)) a[k++] = b[j];
            sum = 0;
            //memset(vis,0,sizeof(vis); 这句加上就超时。。。
            dfs(k, 0);
            ans += sum;
        }
        printf("%d\n", ans);
    }
    return 0;
}





智能网联汽车的安全员高级考试涉及多个方面的专业知识,包括但不限于自动驾驶技术原理、车辆传感器融合、网络安全防护以及法律法规等内容。以下是针对该主题的一些核心知识解析: ### 关于智能网联车安全员高级考试的核心内容 #### 1. 自动驾驶分级标准 国际自动机工程师学会(SAE International)定义了六个级别的自动驾驶等级,从L0到L5[^1]。其中,L3及以上级别需要安全员具备更高的应急处理能力。 #### 2. 车辆感知系统的组成与功能 智能网联车通常配备多种传感器,如激光雷达、毫米波雷达、摄像头和超声波传感器等。这些设备协同工作以实现环境感知、障碍物检测等功能[^2]。 #### 3. 数据通信与网络安全 智能网联车依赖V2X(Vehicle-to-Everything)技术进行数据交换,在此过程中需防范潜在的网络攻击风险,例如中间人攻击或恶意软件入侵[^3]。 #### 4. 法律法规要求 不同国家和地区对于无人驾驶测试及运营有着严格的规定,考生应熟悉当地交通法典中有关自动化驾驶部分的具体条款[^4]。 ```python # 示例代码:模拟简单决策逻辑 def decide_action(sensor_data): if sensor_data['obstacle'] and not sensor_data['emergency']: return 'slow_down' elif sensor_data['pedestrian_crossing']: return 'stop_and_yield' else: return 'continue_driving' example_input = {'obstacle': True, 'emergency': False, 'pedestrian_crossing': False} action = decide_action(example_input) print(f"Action to take: {action}") ``` 需要注意的是,“同学”作为特定平台上的学习资源名称,并不提供官方认证的标准答案集;建议通过正规渠道获取教材并参加培训课程来准备此类资格认证考试
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值