码迷,mamicode.com
首页 > 其他好文 > 详细

SGU 乱乱开

时间:2015-07-01 22:12:54      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:

本解题报告 乱抄,乱写,随性随心,不喜多喷!

SGU 142:

    思路:一个string的字串不会超过2^20个,我们枚举出来就好了。

              我出错点:数组RE

技术分享
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<algorithm>
 4 #include<string.h>
 5 #include<string>
 6 #include<iostream>
 7 #include<set>
 8 #include<map>
 9 #include<vector>
10 
11 using namespace std;
12 typedef long long ll;
13 
14 #define N 566666
15 
16 int n;
17 char s[N];
18 bool  b[1<<21];
19 char ss[50];
20 
21 int main()
22 {
23    scanf("%d",&n);
24    scanf("%s",s);
25    int len=20;
26 
27    memset(b,false,sizeof(false));
28 
29    int tot=1<<len;
30 
31    for (int i=0;i<n;i++)
32    {
33       int num=1;
34       for (int j=0;j<len&&i+j<n;j++)
35       {
36               if (s[i+j]==a) 
37               num<<=1;
38               else num=num*2+1;
39          b[num]=true;
40       }
41    }
42 
43    int pos;
44 
45    for (int i=2;i<tot;i++)
46    if (!b[i])
47    {
48        pos=i;
49        break;
50    }
51 
52    int num=floor(log(pos)/log(2));
53   
54    printf("%d\n",num);
55    int tmp=num;
56 
57    while (pos>1)
58    {
59      if (pos&1) ss[tmp--]=b;
60      else ss[tmp--]=a;
61      pos/=2;
62    }
63  
64   for (int i=1;i<=num;i++)
65   printf("%c",ss[i]);
66   
67   printf("\n");  
68    return 0;
69 }
70 
71 
72        
73   
74    
View Code

 

SGU 乱乱开

标签:

原文地址:http://www.cnblogs.com/forgot93/p/4614573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!