Codeforces 328B-Sheldon and Ice Pieces(馋)
1 second
256 megabytes
standard input
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.
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.
Print the required number of instances.
42
23454
2
169
12118999
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(馋)的更多相关文章
- Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题
题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...
- codeforces 686A A. Free Ice Cream(水题)
题目链接: A. Free Ice Cream //#include <bits/stdc++.h> #include <vector> #include <iostre ...
- CodeForces - 1004E Sonya and Ice Cream
题面在这里! 挺智障的一个二分...我还写了好久QWQ,退役算啦 题解见注释... /* 先对每个点记录 向子树外的最长路 和 向子树内最长路,然后二分. 二分的时候枚举链的LCA直接做就好啦. */ ...
- 2013/7/16 HNU_训练赛4
CF328B Sheldon and Ice Pieces 题意:给定一个数字序列,问后面的数字元素能够组成最多的组数. 分析:把2和5,6和9看作是一个元素,然后求出一个最小的组数就可以了. #in ...
- [POJ 3498] March of the Penguins
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4378 Accepted: ...
- POJ 3498 March of the Penguins(网络最大流)
Description Somewhere near the south pole, a number of penguins are standing on a number of ice floe ...
- poj 3498 最大流
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4809 Accepted: ...
- poj 3498 March of the Penguins(拆点+枚举汇点 最大流)
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4873 Accepted: ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
随机推荐
- 用DOS命令获取文件列表
其实就是两个命令:dir 跟 tree 在C:盘根目录下生成了一个名为“filelist.txt”的文本文件,该文件中即包含D:盘的文件夹列表. dir d:\ >c:\filelist.txt ...
- 电商指尖---(6)solrconfig.xml配置具体解释
solrconfig.xml配置文件主要定义SOLR理规则,包含索引数据的存放位置,更新,删除,查询的一些规则配置. 能够在tomcat的安装路径下找到这个文件C:\Program Files\Apa ...
- 中颖电子AD操作
#define ADC_DIS 0 #define ADC_ENB 1 //ADC通道号定义 #define ADC_Chanel0 (unsigned char)(0x00<<1) #d ...
- freemarker该阵列
freemarker该阵列 1.设计思路 (1)声明一个数组 (2)打印数组中的元素 2.设计源代码 <#--freemarker数组--> <#assign nums=[12,34 ...
- 付款页面DEMO
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHRxdWVlbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...
- sqlserver system object type
select distinct s.type, s.type_desc from sys.objects as s inner join (select distinct type from sys. ...
- Mybatis如何SQL声明表名称参数
insert into prefix_${table_name} (a, b, c) values (#{a}, #{b}, #{c}) ${} 它代表了直接使用字面(literal value) # ...
- Android 按下电源按钮关闭小学习过程的整个长度
Android 按下电源按钮关闭小学习过程的整个长度 近期研究了一下android关机跟又一次启动功能,看了一些长按电源键到弹出关机对话框,到真正关机的一系列处理过程. 首先还是来看看这个长按电源键都 ...
- Java 新特性(5) - Java EE 5 新特性
Java EE 5 由 Java Community Process 通过 Java Specification Request 244 发布,这个 “总纲” JSR 指出了详细描述 Java EE ...
- JSP通用7动作命令
JSP通用7动作命令 1.jsp:forward指令 运行页面转向.将请求处理转发到下一个页面 2.jsp:param指令 用于传递參数 3.jsp:include指令 用于动态引入 ...