Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不是ans = n;……是1

Posted by frkstyc at 2005-08-04 16:58:16 on Problem 2406
In Reply To:。。。。为什么能过官方数据+uva数据的程序在这里wa,难道是我的rp出了问题? Posted by:Maximum at 2005-08-04 16:57:20
> #include <stdio.h>
> #include <string.h>
> 
> const int MAX = 1000000+10;
> 
> char line[MAX];
> int n, nextval[MAX];
> 
> main() {
> //   freopen("10298.in", "r", stdin);
> //   freopen("10298.out", "w", stdout);
>    
>    while (gets(line) && strcmp(line, ".")) {
>       n = strlen(line);
>       memmove(line + 1, line, n);
>       
>       int i, pos;
>       pos = nextval[1] = 0;
>       for (i = 2; i <= n; i++) {
>          while (pos && line[pos + 1] != line[i])
>             pos = nextval[pos];
>          if (line[pos + 1] == line[i]) pos++;
>          nextval[i] = pos;
>       }
>       
>       int sub = n - nextval[n], ans;
>       if (n % sub == 0) ans = n / sub;
>       else ans = n;
>       
>       printf("%d\n", ans);
>    }
>    
>    return 0;         
> }   

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator