Codeforces Round #239 --B


                                                       B. Garland
  time limit per test     1 second           memory limit per test      256 megabytes
  input      standard input  
  output    standard output

Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and boughtn colored sheets of paper, the area of each sheet is 1 square meter.

The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.

Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​m pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.

Input

The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.

The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.

Output

Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.

Sample test(s)
Input
aaabbac
aabbccac
Output
6
Input
a
z
Output
-1
Note

In the first test sample Vasya can make an garland of area 6: he can use both sheets of colorb, three (but not four) sheets of colora and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.

In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of colorz.

题意:第一行输入的是n 种材料, 第二行输入的是要做成的花环所需的材料。可以用哈希,比如提供的材料里有4个a(只看a), 而做花环只需用3个a, 则此时用的材料的最大值为3,即从4个里直接取3个即可, 如果需用5个,则可以这样理解,先把提供的材料用掉3个,则还剩一个,但我现在还需要2个a颜色,那怎么办? 别急,题目中说可以把材料分割,那么我就可以把最后一个材料分割成2份, 那就可以满足要求了。 但如果我要用的材料在我所拥有的材料之外,那么直接输出-1即可。


#include<stdio.h>

int main()
{
	int i, j, a[1001]={0}, b[1001]={0}, count = 0;
	char str[1001];
	gets(str);
	for(i=0; str[i]!='\0'; i++)
	{
		 a[str[i]-'a'] ++;
	}
	gets(str);
	for(j=0; str[j]!='\0'; j++)
	{
		b[str[j]-'a']++;
	}
	for(i=0; i<26; i++)
	{
		if(a[i]!=0)
		{
			if(a[i] >= b[i])
				count += b[i];
			else
				count += a[i];
		}
		else
			if(b[i]!=0)
			{
				printf("-1\n");
				return 0;
			}
	}
	printf("%d\n", count);
return 0;
}

转载于:https://www.cnblogs.com/6bing/p/3931253.html

标题基于Python的自主学习系统后端设计与实现AI更换标题第1章引言介绍自主学习系统的研究背景、意义、现状以及本文的研究方法和创新点。1.1研究背景与意义阐述自主学习系统在教育技术领域的重要性和应用价值。1.2国内外研究现状分析国内外在自主学习系统后端技术方面的研究进展。1.3研究方法与创新点概述本文采用Python技术栈的设计方法和系统创新点。第2章相关理论与技术总结自主学习系统后端开发的相关理论和技术基础。2.1自主学习系统理论阐述自主学习系统的定义、特征和理论基础。2.2Python后端技术栈介绍DjangoFlask等Python后端框架及其适用场景。2.3数据库技术讨论关系型和非关系型数据库在系统中的应用方案。第3章系统设计与实现详细介绍自主学习系统后端的设计方案和实现过程。3.1系统架构设计提出基于微服务的系统架构设计方案。3.2核心模块设计详细说明用户管理、学习资源管理、进度跟踪等核心模块设计。3.3关键技术实现阐述个性化推荐算法、学习行为分析等关键技术的实现。第4章系统测试与评估对系统进行功能测试和性能评估。4.1测试环境与方法介绍测试环境配置和采用的测试方法。4.2功能测试结果展示各功能模块的测试结果和问题修复情况。4.3性能评估分析分析系统在高并发等场景下的性能表现。第5章结论与展望总结研究成果并提出未来改进方向。5.1研究结论概括系统设计的主要成果和技术创新。5.2未来展望指出系统局限性并提出后续优化方向。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值