Xinjiang University ACM-ICPC Programming Competition May Competition (Synchronous Competition) B Teacher Yang's Game (full permutation and enumeration)

Mr. Yang played a game for the students, asking them to use multiplication and subtraction to represent a number. He gave everyone 9 cards, and then reported a number, and asked everyone to express the number in the form of an expression.
100 can be expressed like this Form: 100 = 129*67-8543, can also be expressed as: 100 = 13*489-6257
Note: In the expression, the numbers 1~9 appear respectively and only once (excluding 0).
For expressions like this, 100 has 20 representations.
Question requirements:
Read a positive integer N (N<1000 * 1000) from the standard input, and the
program outputs all the numbers composed of the numbers 1~9 without repetition and omission.
Note: It is not required to output every representation, only count how many representations there are!
Input description:
A positive integer N
Output description:
How many representations are there for the output
Example 1
Input
100
Output
20
Remarks:

Note that there is only one multiplication and one subtraction, and the * sign is guaranteed to be in front of the -

Idea: I always thought it was a formula title, but found it to be a violent enumeration

Arrange all 1-9, then take a part of a, a part of b, and a part of c, and the enumeration can be stored in the array

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
ll ant[1000005]= {0};
ll p[9]= {1,2,3,4,5,6,7,8,9};
intmain()
{
    ll a,b,c,ans;
//  memset(a,0,sizeof(a));
    do
    {
 
        for(int i=0; i<=6; i++)
            for(int j=i+1; j<=7; j++)
            {
                a=b=c=ans=0;
                for(int k=0; k<=i; k++)
                    a=a*10+p[k];
 
                for(int k=i+1; k<=j; k++)
                    b=b*10+p[k];
 
                for(int k=j+1; k<=8; k++)
                    c=c*10+p[k];
                years = b*ca;
                if(b*c-a<1000001&&b*c-a>=0)
                    ant[years]++;
            }
    }
    while(next_permutation(p,p+9));
    int n;
    cin>>n;
    cout<<ant[n]<<endl;
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325681920&siteId=291194637