CF Set of Strings
1 second
256 megabytes
standard input
standard output
You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q (formally, s1 + s2 + ... + sk = q) and the first characters of these strings are distinct.
Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist.
The first line contains a positive integer k (1 ≤ k ≤ 26) — the number of strings that should be in a beautiful sequence.
The second line contains string q, consisting of lowercase Latin letters. The length of the string is within range from 1to 100, inclusive.
If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next k lines print the beautiful sequence of strings s1, s2, ..., sk.
If there are multiple possible answers, print any of them.
1
abca
YES
abca
2
aaacas
YES
aaa
cas
4
abc
NO
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <map>
#include <ctime>
using namespace std; bool VIS[];
int main(void)
{
char q[];
int a,num;
int loc[];
num = ; scanf("%d",&a);
scanf("%s",q);
for(int i = ;q[i];i ++)
if(!VIS[q[i]])
{
VIS[q[i]] = true;
loc[num] = i;
num ++;
}
loc[num] = strlen(q); if(num < a)
puts("NO");
else
{
puts("YES");
for(int i = ;i < a;i ++)
{
if(i == a - )
for(int j = loc[i];q[j];j ++)
printf("%c",q[j]);
else
for(int j = loc[i];j < loc[i + ];j ++)
printf("%c",q[j]);
puts("");
}
} return ;
}
CF Set of Strings的更多相关文章
- CF Vitaly and Strings
Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CF 543C Remembering Strings
https://cn.vjudge.net/problem/CodeForces-543C 题目 You have multiset of n strings of the same length, ...
- CF 149E Martian Strings 后缀自动机
这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...
- CF 452E. Three strings(后缀数组+并查集)
传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次, ...
- cf 762C. Two strings
因为要删去1个串(读错题),所以就直接二分搞就好了. 需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了. #include<bits/stdc++.h> ...
- cf 223B.Two Strings
神奇(%%题解) 题意:判断B串作为A串的子序列,不是不可以把A全部覆盖掉. 这样的话就是判断是不是A[i]最右匹配B的点和最左匹配B的点相交(重合)就好.(不重合的话B自然会空出中间一段,那么肯定不 ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- CF 1083 B. The Fair Nut and Strings
B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析: 建出trie树,给定的两个字符串就 ...
- CF#358 D. Alyona and Strings DP
D. Alyona and Strings 题意 给出两个字符串s,t,让找出最长的k个在s,t不相交的公共子串. 思路 看了好几个题解才搞懂. 代码中有注释 代码 #include<bits/ ...
随机推荐
- 联想硬盘分区表格式修改 GPT -> MBR
知识点分析:随机预装Win8的电脑,磁盘为GPT格式的,如果需要安装Win7等早期版本系统,需要转换为MBR格式的,使用Diskpart命令即可完成转换. 操作步骤: 注意:转换磁盘格式需要清空磁盘中 ...
- OC:copy 与 retain 的区别
copy与retain的区别: copy是创建一个新对象,retain是创建一个指针,引用对象计数加1.Copy属性表示两个对象内容相同,新的对象retain为1 ,与旧有对象的引用计数无关,旧有对象 ...
- angularjs directive学习心得
一些常见的错误 在angularjs里,创建directive时,directive的名称应该要使用驼峰式,例如myDirective,而在html里要调用它的时候,就不能用驼峰式了,可以用my-di ...
- pad 横屏 cell不正常显示
在iOS9中,适配iPad横屏的时候,我发现cell不能正常显示,其标题和线都不是从左边头部开始,而是在中间,accessoryType的图标也不再右边尾部,效果如下图 但是在iPhone中是正常的, ...
- radvd.conf RADVD配置文件内容部分解析
interface eth0{ AdvSendAdvert on; #启用路由器公告(RA)功能 MinRtrAdvInterval ; #每隔30-100秒间隔发送公告消息 MaxRtrAdvInt ...
- Cocos2dx Widget button透明区域过滤
小伟哥 遇到一个命题: button透明区域过滤.当点击一个建筑button.花的时候不得不想一些方法把点击透明区域过滤掉. 让点击也没有效果滴啦. 開始搜索了半天才有所思路. 在网络上非常多贴代码的 ...
- 试读《基于MVC的JavaScript Web富应用开发》
前两年做jsp开发时,用了不少JavaScript(JS)和Ajax, 最近的项目一直在使用Flex做前台,虽然也有类似的ActionScript实现JS的功能,但没想到的是,短短几年JS发展如此迅速 ...
- 项目优化经验分享(八)TeamLeader经验总结
引言 通过前面的七篇博客.我把自己在项目优化过程的经验进行了分享,今天这篇博客,作为一个总结,就来讲讲作为一个TeamLeader,在项目管理中遇到的问题和解决经验! 正文 问题一:团队之间怎么沟通? ...
- cocos2d-x android 字体的设置
我们知道 ios 自带的字体 和 android 自带的字体不同 为了使我们开发的游戏中的字体统一 我们就需要自己的字体(包括从mac 拷贝出来的 字体) 从 mac 中 copy 出 Thonbur ...
- oc-13-多文件
Dog.h #import <Foundation/Foundation.h> @interface Dog : NSObject { @public NSString *_name; i ...