CF70B.Text Messaging
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split!
Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space).
The little walrus's text looks in the following manner:
TEXT ::= SENTENCE | SENTENCE SPACE TEXT
SENTENCE ::= WORD SPACE SENTENCE | WORD END
END ::= {'.', '?', '!'}
WORD ::= LETTER | LETTER WORD
LETTER ::= {'a'..'z', 'A'..'Z'}
SPACE ::= ' '
SPACE stands for the symbol of a space.
So, how many messages did Fangy send?
小海象 Fangy 和所有现代海象一样,喜欢通过短信交流。有一天,他遇到了如下问题:当他发送大段文本时,文本会被分割为若干部分,每部分恰好包含 n 个字符(即一条短信的容量)。因此,完整的句子和单词常常被截断!
Fangy 对此很不满意,于是决定自行将文本划分为最少数量的短信,使得每条短信中均不出现被截断的句子,且所用短信总数最少。若两个相邻句子被分到不同的短信中,则它们之间的空格可被忽略(Fangy 不会发送该空格)。
小海象的文本格式定义如下:
TEXT ::= SENTENCE | SENTENCE SPACE TEXT
SENTENCE ::= WORD SPACE SENTENCE | WORD END
END ::= {'.', '?', '!'}
WORD ::= LETTER | LETTER WORD
LETTER ::= {'a'..'z', 'A'..'Z'}
SPACE ::= ' '
其中,SPACE 表示空格字符。
那么,Fangy 共发送了多少条短信?
输入格式
The first line contains an integer n, which is the size of one message (2 ≤ n ≤ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty.
第一行包含一个整数 n,表示一条消息的大小(2 ≤ n ≤ 255)。第二行包含文本,文本长度不超过 104 个字符。保证该文本满足上述描述的格式。特别地,这意味着文本非空。
输出格式
On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes.
在第一行且仅在第一行输出 Fangy 所需的短信条数。如果无法将文本分割,则输出 Impossible(不带引号)。
输入输出样例
输入#1
25 Hello. I am a little walrus.
输出#1
2
输入#2
2 How are you?
输出#2
Impossible
输入#3
19 Hello! Do you like fish? Why?
输出#3
3
说明/提示
Let's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".
我们来看第三个样例。文本将被分割为三条消息:“Hello!”、“Do you like fish?” 和 “Why?”。
输入解题思路,AI测评打分。不知道怎么写?