usaco5.5-Hidden Passwords


最小表示法,感觉可以做成个模板,第一次RE是因为字符串长度变2倍了而我把数组开小了

Executing...
   Test 1: TEST OK [0.008 secs, 3760 KB]
   Test 2: TEST OK [0.005 secs, 3760 KB]
   Test 3: TEST OK [0.005 secs, 3760 KB]
   Test 4: TEST OK [0.008 secs, 3760 KB]
   Test 5: TEST OK [0.005 secs, 3760 KB]
   Test 6: TEST OK [0.003 secs, 3760 KB]
   Test 7: TEST OK [0.008 secs, 3760 KB]
   Test 8: TEST OK [0.008 secs, 3760 KB]
   Test 9: TEST OK [0.024 secs, 3760 KB]
   Test 10: TEST OK [0.014 secs, 3760 KB]
   Test 11: TEST OK [0.019 secs, 3760 KB]
   Test 12: TEST OK [0.005 secs, 3760 KB]
   Test 13: TEST OK [0.003 secs, 3760 KB]
   Test 14: TEST OK [0.008 secs, 3760 KB]

All tests OK.



 1 #include <iostream>

 2 #include <stdio.h>

 3 #include <string.h>

 4 using namespace std;

 5 

 6 char getch2()

 7 {

 8     char c;

 9     while(c=getchar(),c=='\n');

10     return c;

11 }

12 

13 char a[200010];

14 char strTmp[200010];

15 int main()

16 {

17     freopen("hidden.in","r",stdin);

18     freopen("hidden.out","w",stdout);

19     int n;

20     cin>>n;

21 

22     for(int i=0;i<n;i++)

23     {

24         a[i]=getch2();

25     }

26 

27     a[n]='\0';

28 

29 

30     strcpy(strTmp,a);

31     strcat(a,strTmp);

32 

33     int i=0,j=1;

34     while(j<n)

35     {

36         int k;

37         for(k=0;k<n;k++)

38         {

39             if(a[i+k]!=a[j+k])

40                 break;

41         }

42         if(k==n)

43             break;

44         if(a[i+k]>a[j+k])

45             i+=k+1;

46         if(a[i+k]<a[j+k])

47             j+=k+1;

48 

49         if(i==j)

50             j++;

51     }

52 

53     cout<<i<<endl;

54     return 0;

55 }

 

你可能感兴趣的:(password)