codeforces 408B Garland
来源:互联网 发布:linux域名绑定ip 编辑:程序博客网 时间:2024/06/01 08:23
地址: http://codeforces.com/problemset/problem/408/B
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.
aaabbacaabbccac
6
az
-1
代码:
#include <stdio.h>#include <string.h>int main(){char n[1005];char m[1005];int N[26];int M[26];while (scanf("%s%s", n, m) != EOF){int len_n = strlen(n);int len_m = strlen(m);memset(N, 0, sizeof(N));memset(M, 0, sizeof(M));for (int i = 0; i < len_n; i++)N[n[i] - 'a']++;for (int i = 0; i < len_m; i++)M[m[i] - 'a']++;int sign = 1, ans = 0;for (int i = 0; i < 26; i++){if (0 == N[i] && 0 != M[i]){sign = 0;puts("-1");break;}else if (N[i] < M[i])ans += N[i];elseans += M[i];}if (sign)printf("%d\n", ans);}return 0;}
- codeforces 408B Garland
- 【codeforces 758B】Blown Garland
- Codeforces #392 B. Blown Garland
- Codeforces 758B-Blown Garland
- CodeForces 758B Blown Garland
- Codeforence 408 B. Garland
- CF - 408 - B. Garland
- Codeforces Round #239 (Div. 2) B. Garland
- code forces 408B Garland
- Garland(CodeForces
- B. Garland
- CF-Codeforces Round #392 (Div. 2)-B-Blown Garland
- Codeforces Round #392 (Div. 2) B - Blown Garland
- Codeforces Round #392 (Div. 2)-B. Blown Garland(水题)
- Codeforces Round #392(Div. 2) B Blown Garland【暴力枚举】
- Codeforces Round #392 (Div. 2)B Blown Garland
- Codeforces Round #392 (Div. 2) B.Blown Garland(水题)
- Codeforces Round #392 (Div. 2) B. Blown Garland
- git:elmentary os 搭建ssh服务
- Bean Validation
- HTML 5核心内容
- Struts2文件下载
- AjaxToolKit--AutoComplete的介绍
- codeforces 408B Garland
- telnet 实验总结
- 【面向对象常见面试题】访问声明的几点说明(xx)
- 点到直线的距离opencv实现
- 设计模式之——工厂三姐妹
- android 关于包的用法
- 逆波兰表达式学习
- 手机再也不能给孩子玩了,太可怕了!
- 过去,回不去了