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


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

  • 相关阅读:
    断开ssh链接在后台继续运行命令
    linux 隐藏显示终端光标
    shell脚本中echo显示内容带颜色
    Linux/Unix下pid文件作用浅析
    使用autotools自动生成Makefile并在此之上使用dh-make生成可发布的deb程序包(详解)
    Linux的tmpfs文件系统
    kernel编译
    Qt之读取配置文件
    android之TCP客户端框架
    android之模拟器更新底层
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4847760.html
Copyright © 2011-2022 走看看