链接:https://codeforces.com/problemset/problem/328/B
Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry".
Sheldon favourite number is t. He wants to have as many instances of t as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.
Input
The first line contains integer t (1 ≤ t ≤ 10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.
Output
Print the required number of instances.
Examples
input
Copy
42 23454
output
Copy
2
input
Copy
169 12118999
output
Copy
1
Note
This problem contains very weak pretests.
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<queue>
#include<algorithm>
#include<cstdlib>
using namespace std;
long long t,g,r,n;
char a[1001];
int b[1001];
map<int,int>m,p;
int main()
{
cin>>t;
cin>>a;
n=strlen(a);
for(int i=0;i<n;i++)
{
b[i+1]=a[i]-'0';
m[b[i+1]]++;
}
int min1=1000;
while(t)
{
int x=t%10;
t/=10;
p[x]++;
}
for(int i=0;i<=9;i++)
{
if(p[i]!=0)
{
if(i==2||i==5)
min1=min(min1,(m[2]+m[5])/(p[2]+p[5]));
else if(i==9||i==6)
min1=min(min1,(m[6]+m[9])/(p[6]+p[9]));
else
min1=min(min1,m[i]/p[i]);
}
}
cout<<min1;
return 0;
}