Description
Lele was bored recently in class, so he invented a digital game to pass the time. This game is like this. First, he took out a few pieces of paper and wrote any number between 0 and 9 (a number can be re-rewritten). Then, he asked his classmates to write two numbers, X and K. What Lele wants to do is to fight these cards again to form a digital T, and t + X is a positive integer multiple of K. Sometimes, when there are a lot of pieces of paper, Lele often cannot be spelled out in a lesson, but he wants to know the answer, so he wants to ask you to write a program to calculate the answer.
Input description input description
The first line of 1 contains two integers, N and M (0 <n <9, 0 <m <2000), representing the number of pieces of paper and the number of inquiries respectively.
2 The second row contains N integers representing the numbers written on the paper. Each number may be 0 ~ 9.
3. Then there are m rows for each query. Each query is given two integers x and K (0 <= x <10 ^ 9,0 <k <100 ).
Output description
4. For each query, if the T matching the answer can be spelled out using the paper, The result t will be output. If multiple results exist, the minimum t meeting the requirements is output.
5. If it cannot be spelled out, "NONE" is output ".
Sample Input
4 3
1 2 3 4
5 7
33 6
12 8
Sample output sample output
1234
None
1324
// Train of thought: the list of N numbers.
#include<iostream>#include<vector>#include<algorithm>using namespace std;bool test(const vector<int> &v,int x,int k){int result=0;for(int i=0;i<v.size();i++){result=10*result+v[i];}if((result+x)%k==0) return true;else return false;}int main(){int n,m;cin>>n>>m;vector<int> v(n);for(int i=0;i<n;i++) cin>>v[i];for(int i=0;i<m;i++){int x,k;cin>>x>>k;sort(v.begin(),v.end());bool flag=false;do{if(test(v,x,k)){flag=true;break;}}while(next_permutation(v.begin(),v.end()));if(flag==false) {cout<<"None"<<endl;continue;}for(int i=0;i<v.size();i++){cout<<v[i];}cout<<endl;}}
1229 digital games