读书人

一道ACM的试题解决思路

发布时间: 2012-03-03 15:33:02 作者: rapoo

一道ACM的试题
最近老师给我出了一道ACM的试题,可是研究了好就还是没有做出来,请教各位帮我研究一下.先谢谢大家了
Given two strings a and b we define a*b to be their concatenation.For example ,if a = "abc " and b= "def " then a*b= "abcdef ".If we think of integer is defined in the normal way:a^0= " "(the empty string) and a^(n+1) =a*(a^n)
.
Input
Each test case is a line of input representing s,a string of printable characters.
Output
For each s you should print the largest n such that s=a^n for some string a
. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a peried follows the last test case.
Sample Input
abcd
aaaa
ababab.
Sample Output
1
4
3

[解决办法]
找出字符串中出现的周期子字符串的出现次数
[解决办法]
有空了再看吧 ~~
[解决办法]
做好后可以来这里测试:)
http://acm.fjnu.edu.cn/show?problem_id=1528
[解决办法]
...
这么多天了还米人回~

acm的题目偶不大愿意把程序贴上来


给算法好了

假设串的长度为n,那么所求的就是n的某个因子,把因子从大到小去试就好

加速的想法,答案必是串中出现次数最少的字符的出现次数的因子,依然从大到小试


偶但是的程序在这里(http://acm.fjnu.edu.cn/show?problem_id=1528)的结果


------------------------------
Memory Time Language Code Length
1296K 0.12S C++ 825
----------------------------------
[解决办法]
晕,怎么看不懂啊?是这个意思吗?
int main()
{
char s[20];int i=0;int num=0;

gets(s);
while(s[i]!=0)
{
if(s[i]== 'a ')
num++;
i++;
}
printf( "%d\n ",num);

return 0;
}

[解决办法]
The length of s will be at least 1 and will not exceed 1 million characters

---------------------------------
不超过一百万个字符
用string类型?
[解决办法]
统计所有字符出现的次数,去他们的最大公约数,再对最大公约数分解质因数...

读书人网 >C语言

热点推荐