返回信息流题目描述
Study sister plays the game coc everyday. Now she wants to upgrade her wizard in laboratory,but she doesn't know the spell. After research, she finds out that the spells are made by repeat the keyword M times. She checks top players' daily log and get one of their upgrade log.
Now she wants to know how many possible spells are in the log.
输入格式
There are several test cases. For each case, the first line consist of two integer M, L, (M*L <= 1e5) means the repeat time and the lenth of the keyword. Next line contains a string means the log. The string is made by lowercase letter.
update: |s| <=1e5
输出格式
For each test case, print one line, the number of the possible spells.
输入样例
3 3
abcabcabcabc输出样例
4
hint:
The four possible spells are:
abcabcabc
bcabcabca
cabcabcab
abcabcabc
[ema1]
我的代码:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int rep, len, sum = 0;//rep为keyword重复次数,len为keyword长度。sum为可能的种类数目
string st;//log
cin >> rep >> len;
cin >> st;
if (st.size() == 0 || len <= 0 || st.size() < (len*rep)||rep<=0) //排除几种特殊情况
{
cout << sum << endl;
return sum;
}
//计算重复次数为1时,spells的种类
if (rep == 1) { sum = st.size() - len + 1; cout << sum << endl;return sum; }
//两重循环计算spells的可能数
//第一重循环,len次。第二重遍历一次string。
for (int i = 0; i <len; ++i)
{
int con = 0;
for (int j = i + len; j < st.size(); j += len)
{
//这个if加三目运算符的用法是为了把所有比较结果都利用起来
//时间复杂度比暴力枚举稍微好一点点。
if (st.substr(j - len, len) == st.substr(j, len))
( con == (rep-2) )? sum++ : con++;
else con = 0;
}
}
cout << sum << endl;
return sum;
}
[ema1]我的疑惑,不知道是不是输入、输出格式不对,还是忽略了一些特殊情况。代码总是不能通过。
求各位大神指导。
LZ是新手,求指导!!
这是一条镜像帖。来源:北邮人论坛 / acm-icpc / #89285同步于 2016/3/26
该镜像源已超过 30 天没有更新,可能在源站已被删除。
ACM_ICPC机器人发帖
《新手求指导》热身赛3 B题求指导!(内附我自己的代码)
Mrxiaobai
2016/3/26镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
There are several test cases. For each case, the first line consist of two integer M, L, (M*L <= 1e5) means the repeat time and the lenth of the keyword. Next line contains a string means the log. The string is made by lowercase letter.
所以就是输入写的不对吗?对oj系统不熟悉啊。求明示
【 在 samuelwyf 的大作中提到: 】
: There are several test cases. For each case, the first line consist of two integer M, L, (M*L <= 1e5
: .........
多谢指点~~虽然今天预选还是跪了~~明年再来玩玩~~
【 在 samuelwyf 的大作中提到: 】
: 题目有多组数据
: 【 在 Mrxiaobai 的大作中提到: 】
: : 所以就是输入写的不对吗?对oj系统不熟悉啊。求明示
:
: