博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF 335A(Banana-贪心-priority_queue是大根堆)
阅读量:7079 次
发布时间:2019-06-28

本文共 3049 字,大约阅读时间需要 10 分钟。

 

A. Banana
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets of stickers as she wants, and may specify any string of length n for the sheets, but all the sheets must be identical, so the string is the same for all sheets. Once she attains the sheets of stickers, she will take some of the stickers from the sheets and arrange (in any order) them to form s. Determine the minimum number of sheets she has to buy, and provide a string describing a possible sheet of stickers she should buy.

Input

The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n(1 ≤ n ≤ 1000).

Output

On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print instead a single line with the number -1.

Sample test(s)
input
banana4
output
2baan
input
banana3
output
3nab
input
banana2
output
-1
Note

In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".

 

 

最近的比赛时间都是什么心态。。。

这题贪心很直观了吧。

显然字母可以分开来考虑。。每次选取该字母需要sticker最多的,+上该字母

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i
=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (1000+10)#define MP(a,b) make_pair(a,b) long long mul(long long a,long long b){return (a*b)%F;}long long add(long long a,long long b){return (a+b)%F;}long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}typedef long long ll;typedef pair
pic;int n,m;char s[MAXN],ans[MAXN];int c[MAXN]={0};struct node{ int a,b; char c; node(){} node(int _a,char _c):a(_a),b(1),c(_c){} int v(){return a/b+(bool)(a%b);} friend bool operator<(node a,node b){return a.v()
h;int main(){// freopen(".in","r",stdin);// freopen(".out","w",stdout); scanf("%s%d",s+1,&m);ans[m+1]=0;n=strlen(s+1); For(i,n) c[s[i]]++; for(int i='a';i<='z';i++) if (c[i]) h.push(node(c[i],i)),ans[h.size()]=i; if (h.size()>m) cout<<"-1"<

 

 

转载地址:http://ryvml.baihongyu.com/

你可能感兴趣的文章
Yii1.1应用升级到Yii2.0的一些注意点
查看>>
dede使用方法----调用导航
查看>>
最低位 【杭电-HDOJ-1196】 附题
查看>>
结构化方法、面向对象方法的区别
查看>>
算法笔记_192:历届试题 买不到的数目(Java)
查看>>
WebViewJavascriptBridge-Obj-C和JavaScript互通消息的桥梁
查看>>
linux启动基本流程
查看>>
VB.NET+三层 机房收费系统之组合查询
查看>>
MetaSploit攻击实例讲解------工具Meterpreter常用功能介绍(kali linux 2016.2(rolling))(详细)...
查看>>
JavaScript面向对象之类的创建
查看>>
IPsec ISAKMP(转)
查看>>
jquery js解析函数、函数直接调用
查看>>
对于eclipse building workspaces 慢的问题,解决方法
查看>>
ORACLE-行转列
查看>>
Java线程池关闭1-shutdown和isTerminated<转>
查看>>
【论文:麦克风阵列增强】An Algorithm For Linearly Constrained Adaptive Array Processing
查看>>
JPA相关注解
查看>>
HTML导航 - 点击更改背景
查看>>
leetcode 链表 Partition List
查看>>
织梦在服务器上面安装的时候一直提示data文件没有权限,可我已经写了权限,还是提示...
查看>>