六年级xxs博主写文章不容易,点个免费的关注吧
(实在不行点个赞也行啊)
在做training训练时,如果不习惯用文件输入输出的话可以去洛谷上找这道题然后做,最后加上那几行代码即可
(This poorly named task has nothing to do with prime numbers or even, really, prime digits. Sorry 'bout that.)
A cryptarithm is usually presented as a pencil-and-paper task in which the solver is required to substitute a digit for each of the asterisks (or, often, letters) in the manual evaluation of an arithmetic term or expression so that the consistent application of the digits results in a proper expression. A classic example is this cryptarithm, shown with its unique solution:
SEND 9567 S->9 E->5 N->6 D->7 + MORE + 1085 M->1 O->0 R->8 ------- ------- MONEY 10652 Y->2The following cryptarithm is a multiplication problem that can be solved by substituting digits from a specified set of N digits into the positions marked with *. Since the asterisks are generic, any digit from the input set can be used for any of the asterisks; any digit may be duplicated as many times as desired.
Consider using the set {2,3,5,7} for the cryptarithm below:
* * * x * * ------- * * * <-- partial product 1 -- MUST BE 3 DIGITS LONG * * * <-- partial product 2 -- MUST BE 3 DIGITS LONG ------- * * * *Digits can appear only in places marked by `*'. Of course, leading zeroes are not allowed.The partial products must be three digits long, even though the general case (see below) might have four digit partial products.
********** Note About Cryptarithm's Multiplication ************
In USA, children are taught to perform multidigit multiplication as described here. Consider multiplying a three digit number whose digits are 'a', 'b', and 'c' by a two digit number whose digits are 'd' and 'e':[Note that this diagram shows far more digits in its results than the required diagram above which has three digit partial products.] a b c <-- number 'abc' x d e <-- number 'de'; the 'x' means 'multiply' ----------- p1 * * * * <-- product of e * abc; first star might be 0 (absent) p2 * * * * <-- product of d * abc; first star might be 0 (absent) ----------- * * * * * <-- sum of p1 and p2 (e*abc + 10*d*abc) == de*abcNote that the 'partial products' are as taught in USA schools. The first partial product is the product of the final digit of the second number and the top number. The second partial product is the product of the first digit of the second number and the top number.
Write a program that will find all solutions to the first cryptarithm above (with three digit partial-products) for any subset of supplied non-zero single-digits. Note that the multiplicands, partial products, and answers must all conform to the cryptarithm's framework.
PROGRAM NAME: crypt1
INPUT FORMAT
Line 1: N, the number of digits that will be used Line 2: N space separated non-zero digits with which to solve the cryptarithm SAMPLE INPUT (file crypt1.in)
5 2 3 4 6 8OUTPUT FORMAT
A single line with the total number of solutions. Here is the one and only solution for the sample input:
2 2 2 x 2 2 ------ 4 4 4 4 4 4 --------- 4 8 8 4SAMPLE OUTPUT (file crypt1.out)
1OUTPUT DETAILS
Here's why 222x22 works: 3 digits times 2 digits yields two (equal!) partial products, each of three digits (as required). The answer has four digits, as required. Each digit used {2, 4, 8} is in the supplied set {2, 3, 4, 6, 8}.
Why 222x23 doesn't work:
2 2 2 <-- OK: three digits, all members of {2, 3, 4, 6, 8} 2 3 <-- OK: two digits, all members of {2, 3, 4, 6, 8} ------ 6 6 6 <-- OK: three digits, all members of {2, 3, 4, 6, 8} 4 4 4 <-- OK: three digits, all members of {2, 3, 4, 6, 8} --------- 5 1 0 6 <-- NOT OK: four digits (good), but 5, 1, and 0 are not in {2, 3, 4, 6, 8}
每日翻译(1/1)
题目大意:
有一个这样子的竖式
***
**
-----------
***
***
------------
****
然后给你n个数,这竖式里的所有数必须都来自这n个数里,问你有多少种成立的可能性
其实这题不如反其道而行之
既然是个三位数*两位数
那么就枚举所有三位数*两位数的情况,只要哪种情况符合就种类数+1
这题唯一一个重点或难点,就是检查这些数是否属于这n个数内
不难看出,竖式中共有五个数:x,y,x*(y/10),x*(y%10),x*y
只要检测这五个数是否符合即可
AC代码如下:
/*
ID:
TASK:crypt1
LANG:C++
*/
# include <iostream>
# include <cstdio>
using namespace std;
# define int long long
int n,sum[10]={};
int a[10];
bool check(int x,int y){
int x1=x;
while(x1){
if(sum[x1%10]==0){
return 0;
}
x1/=10;
}
int y2=y;
while(y2){
if (sum[y2%10]==0){
return 0;
}
y2/=10;
}
int z=x*(y%10);
while(z){
if (sum[z%10]==0){
return 0;
}
z/=10;
}
z=x*(y/10);
while(z){
if (sum[z%10]==0){
return 0;
}
z/=10;
}
z=x*y;
while(z){
if (sum[z%10]==0){
return 0;
}
z/=10;
}
return 1;
}
signed main(){
freopen("crypt1.in","r",stdin);
freopen("crypt1.out","w",stdout);
scanf("%lld",&n);
for (int i=1;i<=n;i++){
int t;
scanf("%lld",&t);
sum[t]=1;
}
int cnt=0;
for (int i=100;i<=999;i++){
for (int j=10;j<=99;j++){
if (check(i,j)&&i*j>=1000&&i*j<=9999&&i*(j%10)>=100&&i*(j%10)<=999&&i*(j/10)<=999&&i*(j/10)>=100){
cnt++;
}
}
}
printf("%lld\n",cnt);
fclose(stdin);
fclose(stdout);
return 0;
}