首页 > 代码库 > HDU4891 The Great Pan 暴力

HDU4891 The Great Pan 暴力

题意:给你字符串,两种模式,每一种模式有相应规则的不同意思,问你这个字符串一共有多少意思

解题思路:合在一起两种模式暴力

解题代码:

  1 // File Name: 1005.cpp  2 // Author: darkdream  3 // Created Time: 2014年07月29日 星期二 15时54分08秒  4   5 #include<vector>  6 #include<list>  7 #include<map>  8 #include<set>  9 #include<deque> 10 #include<stack> 11 #include<bitset> 12 #include<algorithm> 13 #include<functional> 14 #include<numeric> 15 #include<utility> 16 #include<sstream> 17 #include<iostream> 18 #include<iomanip> 19 #include<cstdio> 20 #include<cmath> 21 #include<cstdlib> 22 #include<cstring> 23 #include<ctime> 24  25 using namespace std; 26 #define LL long long  27 LL ans = 0 ; 28 char str1[1000000]; 29 char str[10000000]; 30 int main(){ 31     int n;  32     while(scanf("%d",&n) != EOF) 33     { 34     int len = 0; 35         getchar(); 36         for(int i =1 ;i <= n;i ++) 37         { 38         //    printf("%d\n",i); 39             gets(str1); 40             int len1 = strlen(str1); 41           //  printf("%d\n",len1); 42             for(int j = 0 ;j < len1 ;j++) 43                 str[j+len] = str1[j]; 44             len = len + len1; 45         } 46         int is = 0 ; 47         ans = 1;  48         int t  = 0 ; 49         LL tans = 1 ; 50         int ok = 0 ;  51         for(int i = 0 ;i < len ;i ++) 52         { 53             if(ok == 1) 54                 break; 55             if(is)     56             { 57                if(str[i] ==  ) 58                { 59                     t++; 60                     if(str[i+1] !=  ) 61                     { 62                         tans *=(t+1); 63                         t = 0 ;  64                     } 65                }else if(str[i] == $){ 66                    is = 0 ; 67                    ans = tans * ans; 68                    tans = 1;  69                } 70                if(ans > 100000 || tans > 100000) 71                 { 72                      ok = 1;  73                 } 74             }else { 75              //  printf("****\n"); 76                if(str[i] == {) 77                 { 78             //       printf("****\n"); 79                    int t = 1 ;  80                    int j ; 81                    for(j = i +1; ;j ++) 82                    { 83                        if(str[j] == })  84                            break; 85                        if(str[j] == |) 86                            t ++ ;  87                    } 88                    i = j; 89                    ans *= t ;  90                    if(ans > 100000) 91                    { 92                      ok  = 1;  93                    } 94                 }else{ 95                    if(str[i] == $) 96                        is = 1;  97                 } 98             } 99     //        printf("%I64d %d\n",ans,i);100         }101         if(ans > 100000 || ok )102             printf("doge\n");103         else 104             printf("%I64d\n",ans);105     }106     return 0;107 }
View Code