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


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

  • 相关阅读:
    【OpenCV】SIFT原理与源码分析:方向赋值
    【OpenCV】SIFT原理与源码分析:关键点搜索与定位
    【OpenCV】SIFT原理与源码分析:DoG尺度空间构造
    【OpenCV】SIFT原理与源码分析
    在Android 下写一个检测软件版本号 以自动升级APP 的插件
    Android开发-eclipse+phonegap(Cordova)环境搭建
    phonegap(cordova)从手机app跳转到web页面在跳转回APP本地页面思路
    黑板客爬虫闯关第一关、第二关
    scrapy实战
    scrapy爬虫框架
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4847760.html
Copyright © 2011-2022 走看看