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;
}

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

Codeforces 328B-Sheldon and Ice Pieces(馋)的更多相关文章

  1. Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题

    题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...

  2. codeforces 686A A. Free Ice Cream(水题)

    题目链接: A. Free Ice Cream //#include <bits/stdc++.h> #include <vector> #include <iostre ...

  3. CodeForces - 1004E Sonya and Ice Cream

    题面在这里! 挺智障的一个二分...我还写了好久QWQ,退役算啦 题解见注释... /* 先对每个点记录 向子树外的最长路 和 向子树内最长路,然后二分. 二分的时候枚举链的LCA直接做就好啦. */ ...

  4. 2013/7/16 HNU_训练赛4

    CF328B Sheldon and Ice Pieces 题意:给定一个数字序列,问后面的数字元素能够组成最多的组数. 分析:把2和5,6和9看作是一个元素,然后求出一个最小的组数就可以了. #in ...

  5. [POJ 3498] March of the Penguins

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4378   Accepted:  ...

  6. POJ 3498 March of the Penguins(网络最大流)

    Description Somewhere near the south pole, a number of penguins are standing on a number of ice floe ...

  7. poj 3498 最大流

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4809   Accepted:  ...

  8. poj 3498 March of the Penguins(拆点+枚举汇点 最大流)

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4873   Accepted: ...

  9. DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

    题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...

随机推荐

  1. 上curl java 模拟http请求

    最近,我的项目要求java模拟http请求,获得dns解决 tcp处理过的信息特定的连接. java api提供urlConnection apache提供的httpClient都不能胜任该需求,二次 ...

  2. Win7设置局域网共享

    Win7设置局域网共享 1. 把win7的guest用户开启. 打开win7的控制面板=>用户账号与安全=>用户账户=>管理其他用户=>点击guest用户,进行开启. 2.解决 ...

  3. 猫学习IOS(四)UI半小时就搞定Tom猫

    阿土 首先对影响 下载项目的源材料: Tom猫游戏代码iOS 素材http://blog.csdn.net/u013357243/article/details/44457357 效果图 以前风靡一时 ...

  4. MVC5

    MVC5 不知不觉 又逢年底, 穷的钞票 所剩无几. 朋友圈里 各种装逼, 抹抹眼泪 MVC 继续走起.. 本系列纯属学习笔记,如果哪里有错误或遗漏的地方,希望大家高调指出,当然,我肯定不会低调改正的 ...

  5. 系列五AnkhSvn

    原文:系列五AnkhSvn AnkhSvn介绍 AnkhSVN是一款在VS中管理Subversion的插件,您可以在VS中轻松的提交.更新.添加文件,而不用在命令行或资源管理器中提交.而且该插件属于开 ...

  6. Java中关于OOM的场景及解决方法(转)

    http://developer.51cto.com/art/201112/305696.htm 1.OOM for Heap=>例如:java.lang.OutOfMemoryError: J ...

  7. DNA和纳米(Nano)Fusion技术的发展趋势

    细观国内外有关DNA与Nano技术的报道.不得不承认存在不小的差距,并且差距有继续拉大的趋势. 在我们国内,DNA技术是作为遗产基因来对待的.引用的有关中文參考资料一般比較陈旧.缺少參考价值.在发达国 ...

  8. android 联系数据库

    联系人数据库学习 2011-10-31(这是android2.3在接触db) 简单介绍 Android中联系人的信息都是存储在一个叫contacts2.db的数据库中.该数据库的路径是:/data/d ...

  9. CSS不常见问题汇总

    写css有一段时间了,其间也遇到一些问题,跟大家分享一下 IE10+滚动条自动以藏问题,导致滚动部分页面看起来不正常 html, body {-ms-overflow-style: scrollbar ...

  10. linux 字符界面浏览器 w3m(转)

    最近找到了几个linux终端下使用的浏览器,主要用来测试本机web服务器是否搭建成功.因为我们一般是用ssh客户端连接linux的,所以很需要一个字符界面的浏览器.找了几个显示都不理想,只有w3m用起 ...