牛客多校4 A Ternary String

这是一个关于ternary字符串的数学问题,字符串根据特定规则自我复制,询问在多少秒后字符串会变为空字符串。对于每个测试用例,需要计算并返回这个时间,如果永远不会变为空则输出-1。示例给出了不同输入字符串得到的相应答案。
摘要由CSDN通过智能技术生成

Ternary String
时间限制:C/C++ 4秒,其他语言8秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
A ternary string is a sequence of digits, where each digit is either 0, 1, or 2.
Chiaki has a ternary string s which can self-reproduce. Every second, a digit 0 is inserted after every 1 in the string, and then a digit 1 is inserted after every 2 in the string, and finally the first character will disappear.
For example, 212'' will become11021” after one second, and become “01002110” after another second.
Chiaki would like to know the number of seconds needed until the string become an empty string. As the answer could be very large, she only needs the answer modulo (109 + 7).
输入描述:

There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:
The first line contains a ternary string s (1 ≤ |s| ≤ 105).
It is guaranteed that the sum of all |s| does not exceed 2 x 106.

输出描述:

For each test case, output an integer denoting the answer. If the string never becomes empty, output -1 instead.

示例1
输入
复制

3
000
012
22

输出
复制

3
93
45

题意:给一个由012组成的字符串,在每一秒钟字符‘2’的后面会产生一个1,字符1的后面会产生一个0,然后删除首位字符,问多少秒后字符串为空?
分析:当碰到字符‘0‘, t=t+1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值