首页 > 其他 > 详细

usaco5.5-Hidden Passwords

时间:2014-09-26 22:36:49      阅读:351      评论:0      收藏:0      [点我收藏+]


最小表示法,感觉可以做成个模板,第一次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 }

 

usaco5.5-Hidden Passwords

原文:http://www.cnblogs.com/oneshot/p/3995666.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!