• BNUOJ 35759 The Great Pan


    The Great Pan

    Time Limit: 1000ms
    Memory Limit: 65536KB
    This problem will be judged on HDU. Original ID: 4891
    64-bit integer IO format: %I64d      Java class name: Main
     
    As a programming contest addict, Waybl is always happy to take part in various competitive programming contests. One day, he was competing at a regional contest of Inventing Crappy Problems Contest(ICPC). He tried really hard to solve a "geometry" task without success.

    After the contest, he found that the problem statement is ambiguous! He immediately complained to jury. But problem setter, the Great Pan, told him "There are only four possibilities, why don't you just try all of them and get Accepted?".

    Waybl was really shocked. It is the first time he learned that enumerating problem statement is as useful as trying to solve some ternary search problem by enumerating a subset of possible angle!

    Three years later, while chatting with Ceybl, Waybl was told that some problem "setters" (yeah, other than the Great Pan) could even change the whole problem 30 minutes before the contest end! He was again shocked.

    Now, for a given problem statement, Waybl wants to know how many ways there are to understand it.

    A problem statement contains only newlines and printable ASCII characters (32 ≤ their ASCII code ≤ 127) except '{', '}', '|' and '$'.

    Waybl has already marked all ambiguity in the following two formats:

    1.{A|B|C|D|...} indicates this part could be understand as A or B or C or D or ....
    2.$blah blah$ indicates this part is printed in proportional fonts, it is impossible to determine how many space characters there are.

    Note that A, B, C, D won't be duplicate, but could be empty. (indicate evil problem setters addedclarified it later.)

    Also note that N consecutive spaces lead to N+1 different ways of understanding, not 2N ways.

    It is impossible to escape from "$$" and "{}" markups even with newlines. There won't be nested markups, i.e. something like "${A|B}$" or "{$A$|B}" or "{{A|B}|C}" is prohibited. All markups will be properly matched.
     

    Input

    Input contains several test cases, please process till EOF.
    For each test case, the first line contains an integer n, indicating the line count of this statement. Next n lines is the problem statement.
    1 ≤ n ≤ 1000, size of the input file will not exceed 1024KB.
     

    Output

    For each test case print the number of ways to understand this statement, or "doge" if your answer is more than 105.
     

    Sample Input

    9
    I'll shoot the magic arrow several
     times on the ground, and of course
     the arrow will leave some holes
     on the ground. When you connect
     three holes with three line segments,
     you may get a triangle.
    {|It is hole! Common sense!|
    No Response, Read Problem
     Statement|don't you know what a triangle is?}
    1
    Case $1: = >$
    5
    $/*This is my code printed in
     proportional font, isn't it cool?*/
    printf("Definitely it is cooooooool 
    %d
    ",4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 
    * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4);$
    2
    $Two  space$ and {blue|
    red} color!

    Sample Output

    4
    4
    doge
    6

    Source

     
    解题:{}中的计算中的|的个数,然后ans *= (个数+1)
    $$中连续的空格,每遇到一个连续的空格,求出其长度ans *= (长度+1);
     
    注意要用长整型
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define INF 0x3f3f3f3f
    15 using namespace std;
    16 const int maxn = 1e5;
    17 LL ans;
    18 char str[1000100];
    19 int n,len;
    20 int main(){
    21     int i,a,b,cnt,k,j;
    22     while(~scanf("%d",&n)){
    23         getchar();
    24         len = 0;
    25         ans = 1;
    26         for(i = 0; i < n; i++){
    27             gets(str+len);
    28             len = strlen(str);
    29         }
    30         a = b = 0;
    31         for(i = 0; i < len; i++){
    32             if(a == 0 && str[i] == '$'){
    33                 a = 1;
    34             }else if(str[i] == '{'){
    35                 b = 1;
    36                 j = 0;
    37             }else if(a == 1 && str[i] == '$'){
    38                 a = 0;
    39             }else if(str[i] == '}'){
    40                 b = 0;
    41                 ans *= j+1;
    42                 j = 0;
    43             }
    44             if(a && str[i] == ' '){
    45                 k = 0;
    46                 while(str[i] == ' '){k++;i++;}
    47                 i--;
    48                 ans *= (k+1);
    49             }
    50             if(b && str[i] == '|'){j++;}
    51             if(ans > maxn) break;
    52         }
    53         if(ans > maxn) puts("doge");
    54         else printf("%I64d
    ",ans);
    55     }
    56     return 0;
    57 }
    View Code
     
  • 相关阅读:
    三星t5拆解
    一条 SQL 引发的事故,同事直接被开除!!
    Git 不能提交空目录?我也是醉了!
    Redis 6.0.8 紧急发布,请尽快升级!
    String.format() 图文详解,写得非常好!
    为什么 Redis 要比 Memcached 更火?
    Lambda 表达式入门,这篇够了!
    天啊,为什么我的 Redis 变慢了。。
    写出一手烂代码的 19 条准则!
    Redis 面试一定要知道的 3 个 问题!
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3906783.html
Copyright © 2020-2023  润新知