zoukankan      html  css  js  c++  java
  • 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
    ",ans);
    	}
    	return 0;
    }


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

  • 相关阅读:
    申港集中运营平台Linux测试环境架构搭建
    收获,不止oracle
    Oracle函数
    Apache+php安装和配置 windows
    mysql for windows(服务器)上的配置安装--实例
    软件工程实践总结--爬山成长
    Alpha版本十天冲刺——Day 8
    Alpha版本十天冲刺——Day 2
    软件产品案例分析--K米
    第二次结对编程作业——毕设导师智能匹配
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4847760.html
Copyright © 2011-2022 走看看