【列舉】Prime Cryptarithm
阿新 • • 發佈:2018-12-01
這題的提議超重要啊。一定要仔細讀,靜下心來讀。還有不要受以前做過什麼題聽說過什麼的干擾。學長讓我看這題,並且說這個應該就是素數加密的問題。然後我一直在想素數,看題目提示又不太對勁。再看樣例,懵到不知道這題到底要幹嘛。所以說啊。。。。
然後這題判斷超級多,稍不注意就漏掉了它是幾位數的判斷,然後我就WA 了。
就按照題意模擬+判斷就好了。
順便學了一下HASH, O(1)複雜度
(反正給出的數字都來自於集合{1,2,3,4,5,6,7,8,9})
/**/ #include <cstdio> #include <cstring> #include <cmath> #include <cctype> #include <iostream> #include <algorithm> #include <map> #include <set> #include <vector> #include <string> #include <stack> #include <queue> typedef long long LL; typedef unsigned long long ULL; using namespace std; int h[10]; bool judge(int i) { while(i) { if(!h[i % 10]) return false; i /= 10; } return true; } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int n, x, cnt = 0, la, fi, r1, r2, m; scanf("%d", &n); while(n--) { scanf("%d", &x); h[x] = 1; } for(int i = 100; i < 1000; i++) { if(!judge(i)) continue; for(int j = 10; j < 100; j++) { if(!judge(j)) continue; m = i * j; if(m > 9999 || !judge(m)) continue; la = j % 10; fi = j / 10; r1 = i * la; r2 = i * fi; if(r1 < 100 || r1 > 999) continue; if(r2 < 100 || r2 > 999) continue; if(!judge(r1) || !judge(r2)) continue; cnt++; } } printf("%d\n", cnt); return 0; } /**/