• HDU 4891 The Great Pan (模拟)


    The Great Pan

    题目链接:

    http://acm.hust.edu.cn/vjudge/contest/123554#problem/D

    Description

    ``` 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 '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 2 N 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.

    </big>
    
    
     
    
    
    
    
    ##Input
    <big>
    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.
    </big>
    
    
    
    
    
    
    ##Output
    <big>
    For each test case print the number of ways to understand this statement, or "doge" if your answer is more than 105.
    </big>
     
     
     
    ##Sample Input
    <big>
    

    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!
    </big>
    
    
    ##Sample Output
    <big>
    4
    4
    doge
    6
    </big>
    
    
    
    
    
    <br/>
    ##题意:
    <big>
    计算给定的文字有多少种解释.
    {} 中有 n 个 | 则有 n+1 种解释.
    $$ 中每有 n个连续的空格则有 n+1 种解释.
    不会出现上述两种形式的任何嵌套.
    </big>
    
    
    <br/>
    ##题解:
    <big>
    由于不会出现嵌套,就比较简单了.
    依次对每个出现的关键字符进行标记和计数即可.
    注意:
    数组要开大,否则TLE.
    乘的过程有可能会爆int,要用longlong.
    </big>
    
    
    
    
    <br/>
    ##代码:
    ``` cpp
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <set>
    #include <vector>
    #define LL long long
    #define eps 1e-8
    #define maxn 1010
    #define mod 100000007
    #define inf 0x3f3f3f3f
    #define mid(a,b) ((a+b)>>1)
    #define IN freopen("in.txt","r",stdin);
    using namespace std;
    
    char str[5000000];
    
    int main(int argc, char const *argv[])
    {
        //IN;
    
        int n;
        while(scanf("%d", &n) != EOF)
        {
            getchar();
            LL ans = 1;
            int flag = 0;
            LL cnt = 0;
            bool flag1 = 0, flag2 = 0;
            while(n--) {
                gets(str);
                int len = strlen(str);
                if(flag) continue;
                for(int i=0; i<len; i++) {
                    if(str[i] == '{') cnt = 0, flag1 = 1;
                    else if(str[i] == '}') {
                        flag1 = 0;
                        ans *= cnt + 1;
                        cnt = 0;
                        if(ans > 100000) {
                            flag = 1;
                            break;
                        }
                    }
                    else if(str[i] == '$')  {
                        if(flag1) continue;
                        if(!flag2) cnt = 0, flag2 = 1;
                        else {
                            flag2 = 0;
                            ans *= cnt + 1;
                            cnt = 0;
                            if(ans > 100000) {
                                flag = 1;
                                break;
                            }
                        }
                    }
                    else if(str[i] == '|' && flag1) cnt++;
                    else if(str[i] == ' ' && flag2) {
                        cnt = 0;
                        while(i<len && str[i] == ' ') {
                            cnt++;
                            i++;
                        }
                        ans *= cnt + 1;
                        cnt = 0;
                        if(ans > 100000) {
                            flag = 1;
                            break;
                        }
                        i--;
                    }
                }
            }
    
            if(flag) printf("doge
    ");
            else printf("%lld
    ", ans);
        }
    
        return 0;
    }
    
  • 相关阅读:
    js 日期时间大小比较
    微软开源项目地址
    通过配置host文件实现本地域名任意设置
    如何取消MSSQL自带智能提示步骤,使用第三方智能提示插件
    在Firefox中关闭缓存
    js获取select标签选中的值
    input文本框设置和移除默认值
    Power Designer 16.5 不能设置自增
    Visual Studio 2017 Key激活码
    终于找到方法关闭Siri了,之前是关不掉的必须开着
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5750838.html
Copyright © 2020-2023  润新知