日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

南邮 OJ 1128 An Industrial Spy

發布時間:2024/3/13 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 南邮 OJ 1128 An Industrial Spy 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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; }




總結

以上是生活随笔為你收集整理的南邮 OJ 1128 An Industrial Spy的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。