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 bought n 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.
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.
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.
aaabbac aabbccac
6
a z
-1
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color aand 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 color z.
题意:
给出 N (1 ~ 1000)和 M (1 ~ 1000)两个字符串,N 中每个字母代表一种原材料颜色,可以将每种颜色任意分成N部分,需要用 N 构成 M,输出最多 N 中多少的颜色数量。若不能构成 M ,则输出 -1。
思路:
模拟。脑残又读错了题。问的是最多需要N中的颜色数量,误解成最多能构成 M 中多长的颜色块,必须要构成全部的 M ,而不是一部分 M 。
AC:
#include <cstdio> #include <string.h> #include <algorithm> using namespace std; int main() { char s1[1005], s2[1005]; int c1[30], c2[30]; memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); scanf("%s%s", s1, s2); for (int i = 0; i < strlen(s1); ++i) c1[s1[i] - 'a']++; for (int i = 0; i < strlen(s2); ++i) c2[s2[i] - 'a']++; int sum = 0; for (int i = 0; i < 26; ++i) { if(c2[i] && !c1[i]) { sum = -1; break; } sum += min(c2[i],c1[i]); } printf("%d\n",sum); return 0; }
相关推荐
(精品)园林软件2.6“佳园”GARLAND综合实例.pdf
Grill安装注意事项,内容包括具体安装细则,机器为纯进口
花环视图garland-view-android,:octocat:garlandview在多个内容列表之间无缝转换。由@ramotion制作.zip
园林软件“佳园”GARLAND综合实例.doc 不错的教程
花环景观Garland View在多个内容列表之间无缝切换。我们专门从事针对移动应用程序和网站的自定义UI的设计和编码。请随时关注最新更新:要求iOS 10.0 Xcode 9 迅捷4.0安装您可以通过几种方式安装garland-view : 将...
garland-view-android,在多个内容列表之间无缝过渡,博客附件,效果请查看博客相对应项目。
将raspberry-led-garland目录复制到/opt/raspberry-led-garland或像这样创建符号链接: sudo ln -s /home/jheka/raspberry-led-garland /opt/raspberry-led-garland 配置 在settings.json文件中配置 GPIO LED ...
每个新选项卡上的Darius Garland HD图像。 对于范德比尔特篮球克利夫兰骑士队和NBA的球迷! 每个新选项卡上的Darius Garland HD图像。 对于范德比尔特篮球,克利夫兰骑士和NBA的球迷! 感谢您给予我们5星的评价! ...
Garland View在多个内容列表之间无缝过渡 我们专门从事针对移动应用程序和网站的自定义UI的设计和编码。 请随时关注最新更新: 在其他平台上检查此库: 要求 Android 4.4 KitKat(API lvl 19)或更高版本 您最喜欢的...
Garland Tools API的非官方节点包装器。 用法 npm install garlandtools-api const garlandtools = require('garlandtools-api'); 搜索内容: (await garlandtools.search("hempen yarn"))[0].obj.n // "Hempen ...
语言:한국어 将ffxiv graland翻译为韩语 ffxiv全球glalld bell站点翻译。 安装后,您将通过输入网站自动翻译。 https://garlandtools.org/bell/ 功能(特点) - 2.0矿工/园艺/渔民翻译 - 3.0矿工/花园/渔民翻译 - ...
所有学分归原始作者西蒙·加兰(Simon Garland)所有。 还有其他变体,即: 为什么还有另一个变体? 我不喜欢高亮链接将原始目标颜色组合到目标颜色中,尤其是在日光暗色方案中。 例如,我几乎只使用//来在q中开始...
这是一个存放我的源文件的其中包含有关R中的数据科学,投资和编码的博客文章。 该网站是通过R包。 请阅读其文档以了解如何使用它。 该主题基于,该经过修改以适合我的个人风格。
戈德斯通 为数据提供 。
覆盖源程序即可 懂的来拿吧! 需要图库的联系我
GARLAND软件,最新开发的三维园林景观设计软件。
“佳园” GARLAND软件,最新开发的三维园林景观设计软件。它采用完全自主知识产权的三维CAD平台,包括三维园林景观设计、二维施工图绘制、植物数据库、三维真实感渲染、二维着色表现与图像处理五大基本模块。具有三...
该算法以四边形折叠为基本操作,利用Garland的二次误差度量(QEM)做误差控制,每次折叠操作可以减少3个顶点及6个面片,从而实现比Garland的QEM算法、周昆等的三角形折叠算法更高的简化效率,文中给出多个试验结果说明了该...
JOHN NICKOLLS, IAN BUCK, AND MICHAEL GARLAND, NVIDIA, KEVIN SKADRON, UNIVERSITY OF VIRGINIA March/April 2008 ACM QUEUE NVIDIA构架师的论文,想学cuda可以耐心看看。