CF1107A.Digits Sequence Dividing
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a sequence s consisting of n digits from 1 to 9.
You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one.
More formally: if the resulting division of the sequence is t1,t2,…,tk, where k is the number of element in a division, then for each i from 1 to k−1 the condition ti<ti+1 (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied.
For example, if s=654 then you can divide it into parts [6,54] and it will be suitable division. But if you will divide it into parts [65,4] then it will be bad division because 65>4. If s=123 then you can divide it into parts [1,23], [1,2,3] but not into parts [12,3].
Your task is to find any suitable division for each of the q independent queries.
给你一个由 n 个数字(每个数字为 1 到 9 中的一个)组成的序列 s。
你需要将该序列划分为至少两个段(段是指元素的连续子序列)(换言之,你需要在序列的某些数字之间插入分隔符),使得每个元素恰好属于一个段;并且若将划分结果表示为一串整数,则该整数序列中每一个后续整数都严格大于前一个整数。
更形式化地:设划分结果为 t1,t2,…,tk,其中 k 是划分所得段的数量,则对每个从 1 到 k−1 的 i,都需满足条件 ti<ti+1(此处为数值比较,即按字符串所表示的整数值进行比较)。
例如,若 s=654,则可将其划分为 [6,54],这是一个合法的划分。但若划分为 [65,4],则不合法,因为 65>4。若 s=123,则可划分为 [1,23] 或 [1,2,3],但不能划分为 [12,3]。
你的任务是对每个独立的 q 个询问,找出任意一种合法的划分方案。
输入格式
The first line of the input contains one integer q (1≤q≤300) — the number of queries.
The first line of the i-th query contains one integer number ni (2≤ni≤300) — the number of digits in the i-th query.
The second line of the i-th query contains one string si of length ni consisting only of digits from 1 to 9.
输入的第一行包含一个整数 q(1≤q≤300),表示查询次数。
第 i 次查询的第一行包含一个整数 ni(2≤ni≤300),表示第 i 次查询中数字字符串的长度。
第 i 次查询的第二行包含一个长度为 ni 的字符串 si,该字符串仅由数字 1 到 9 组成。
输出格式
If the sequence of digits in the i-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query.
Otherwise in the first line of the answer to this query print "YES", on the second line print ki — the number of parts in your division of the i-th query sequence and in the third line print ki strings ti,1,ti,2,…,ti,ki — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string si.
See examples for better understanding.
如果第 i 个查询中的数字序列无法按照题目描述的方式划分为至少两个部分,则对该查询仅输出一行 "NO"。
否则,对该查询的答案:第一行输出 "YES";第二行输出 ki —— 即你对第 i 个查询序列所划分出的部分数量;第三行输出 ki 个字符串 ti,1,ti,2,…,ti,ki —— 即你的划分结果。各部分应按原始字符串中数字的顺序输出。这意味着,若将这些部分按顺序拼接(不改变其相对顺序),则得到的字符串即为 si。
参见示例以加深理解。
输入输出样例
输入#1
4 6 654321 4 1337 2 33 4 2122
输出#1
YES 3 6 54 321 YES 3 1 3 37 NO YES 2 21 22
输入解题思路,AI测评打分。不知道怎么写?