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. 【iOS开发-图层】自己定义图层的两种方式

    想要自己定义图层,仅仅须要构建一个类继承CALayer方法 假设让自己定义图层初始化上面就有画好的图形.有两种办法 重写drawInContext方法 自己定义的图层以下的方法.然后必须自己定义的图层 ...

  2. VS2015 C#6.0

    VS2015 C#6.0 中的那些新特性 VS2015在自己机器上确实是装好了,(全部安装的话,在Java SE 开发工具包 会卡顿很长时间,我直接关闭,然后重启电脑,重新修复安装搞定), 想来体验一 ...

  3. 玩转Web之JavaScript(一)-----javaScript语法总结(一) 与鼠标操作有关的语法

    click()  对象.click()  使对象被点击. event.clientX  返回最后一次点击鼠标 X 坐标值: event.clientY  返回最后一次点击鼠标 Y 坐标值: event ...

  4. 分散式-ubuntu12.04安装spark-1.0.0

    1. 安装文档: http://spark.apache.org/docs/latest/spark-standalone.html 2. web UI: master's web UI, which ...

  5. design pattern Builder 生成器设计模式

    其实设计模式可以学习很有趣,你并不需要有这么难啃旱地FOG对我来说,当然,这些都是健康的骨骼啃啃. 在本文中,建造者模式设计一个搞笑的一幕.根据这一模型来学习功夫的方法,哈哈. 基类的第一,设计.那么 ...

  6. UVA 847 - A Multiplication Game(游戏)

    UVA 847 - A Multiplication Game 题目链接 题意:一个数一開始是1,每次轮流乘2-9,谁先大于n谁就赢,问谁胜 思路:博弈,找出必胜态.2-9为stan,10-18为ol ...

  7. ORACLE 创建表空间、用户、授权

    1.创建表空间 create tablespace TEST  logging datafile 'e:\app\administrator\oradata\orcl\TEST.dbf' size 1 ...

  8. 一个人ACM(我们赶上了ACM)

    时间过得真快,不经意间我已经花了两年的大学生活,现在是时候写的东西.纪念馆两年左右的时间,最近一直在玩博客.我写了一个博客.纪念我们终将逝去的青春. 就从报考说起吧.高考成绩一般,自己选择了土建类的学 ...

  9. 解决TD于ie10没有问题,

    .打开命令提示符下,输入 gpedit 回车打开组策略编辑器: .计算机配置-管理模版-全部设置-关闭数据运行保护,双击打开.选择已启用.关闭组策略浏览器. .命令提示符下输入gpupdate/for ...

  10. printf那点事

    1.打印内存地址 #include<stdio.h> int main() { int a; printf("%p\n",&a); //%p打印地址,自己主动加 ...