【codeforces 335A】Banana
【题目链接】:http://codeforces.com/contest/335/problem/A
【题意】
让你构造一个长度为n的字符串;
每次你可以从这个字符串中任意取走字符;
让你求出取的次数最少的字符串,使得取这么多次能够构成所给的字符串s;
输出次数以及这个字符串;
【题解】
从小到大枚举取的次数;
显然取的次数越多,字符串的长度会越短;
根据每个字符出现的次数i;
能够得到这个字符串每个字符y最少应该出现多少次x;
x=(cnt[y]-1)/i + 1;
累加起来;
看看是不是小于等于n;
是的话,把每个字符应该出现的最小次数加进去;剩余的位置随便填’a’就好
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1100;
int num[300],n;
char s[N];
int main(){
//Open();
Close();
cin >> (s+1);
cin >> n;
rep1(i,1,(int) strlen(s+1)){
num[s[i]]++;
}
rep1(i,1,1000){
int now = 0;
for (char t = 'a';t<='z';t++)
if (num[t]){
now+=(num[t]-1)/i + 1;
}
if (now <=n){
cout << i << endl;
string s="";
for (char t = 'a';t<='z';t++)
if (num[t]){
int k = (num[t]-1)/i+1;
rep1(j,1,k) s+=t;
}
while ((int) s.size()<n) s+='a';
cout << s << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
【codeforces 335A】Banana的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 546A】Soldier and Bananas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
随机推荐
- vertical-align到底是个啥
https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align http://phrogz.net/css/vertical-align ...
- HDU 2079 选课时间(母函数模板题)
链接:传送门 思路:母函数模板题 /************************************************************************* > Fil ...
- 【 【henuacm2016级暑期训练】动态规划专题 K】 Really Big Numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 会发现如果x是reallynumber那么x+1也会是reallynumber.... (个位数+1,各位数的和+1了但是整个数也+ ...
- ofbiz初级教程
本教程是ofbiz 基本应用,它涵盖了OFBiz应用程序开发过程的基本原理.目标是使开发人员熟悉最佳实践,编码惯例,基本控制流程以及开发人员对OFBiz定制所需的所有其他方面. 本教程将帮助您在OFB ...
- oracle用户锁定
https://www.cnblogs.com/lostyue/archive/2011/12/06/2278063.html
- Spring+mybatis+struts框架整合的配置具体解释
学了非常久的spring+mybatis+struts.一直都是单个的用他们,或者是两两组合用过,今天总算整合到一起了,配置起来有点麻烦.可是配置完一次之后.就轻松多了,那么框架整合配置具体解释例如以 ...
- [Python + Unit Testing] Write Your First Python Unit Test with pytest
In this lesson you will create a new project with a virtual environment and write your first unit te ...
- java基础——static keyword小节
static 用于修饰成员 修饰成员变量和成员函数 被修饰过的成员的特点: 1.随着类的载入而载入 2.优先于对象而存在 3.被全部对象所共享 4.能够直接被类名调用
- Process Explorer
https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer Ever wondered which program ...
- What is the difference between Web Farm and Web Garden?
https://www.codeproject.com/Articles/114910/What-is-the-difference-between-Web-Farm-and-Web-Ga Clien ...