Codeforces 328B-Sheldon and Ice Pieces(馋)

B. Sheldon and Ice Pieces
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
input
42
23454
output
2
input
169
12118999
output
1
题意:给一个数t,然后给一个串s,然后找s串中最多出现多少次t。

当中对于数字2与5,6与9能够互相替代。有一个办法是把t和s中5都变成2,9都变成6.

官方标签是贪心。

没看出来。感觉还是读题意然后实现

 
     
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int INF=0x3f3f3f3f;
#define LL long long
char s[1000],c[8];
int num[10];
bool is_ok()
{
	for(int i=0;i<strlen(c);i++)
	{
		if(num[c[i]-'0']<1)
		return 0;
		num[c[i]-'0']--;
	}
	return 1;
}
int main()
{
	int t;
	while(scanf("%d",&t)!=EOF)
	{
		memset(num,0,sizeof(num));
		scanf("%s",s);
		sprintf(c,"%d",t);
		for(int i=0;i<strlen(c);i++)
			if(c[i]=='9')
				c[i]='6';
			else if(c[i]=='5')
				c[i]='2';
		for(int i=0;i<strlen(s);i++)
		{
			if(s[i]=='9')
				s[i]='6';
			if(s[i]=='5')
				s[i]='2';
			num[s[i]-'0']++;
		}
		int ans=0;
		//for(int i=0;i<strlen(c);i++)cout<<num[c[i]-'0']<<" ";cout<<endl;
		while(1)
		{
			if(is_ok())
				ans++;
			else
				break;
		}
		printf("%d\n",ans);
	}
	return 0;
}


版权声明:本文博主原创文章,博客,未经同意不得转载。

转载于:https://www.cnblogs.com/mengfanrong/p/4847760.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值