zoukankan      html  css  js  c++  java
  • HDU 4891— The Great Pan


    The Great Pan

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 893    Accepted Submission(s): 308


    Problem 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 '$'.

    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 than105.
     

    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
     
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int n, len, i, j, flag1, flag2;
        char s[1000001];
       long long cnt1, cnt2, sum1, sum2, ans;
    
        while(~scanf("%d", &n))
        {
            memset(s, '', sizeof(s));
            cnt1 = 1;
            cnt2 = 1;
            sum1 = 0;
            sum2 = 0;
            ans=1;
            flag1=flag2=0;
    
          for(i=0; i<=n; i++){
              gets(s+strlen(s));
           }
    
            len = strlen(s);
            for(i=0; i<len; i++)
            {
                if(s[i]=='{')
                {
                    flag1=1;
                }
                if(flag1)
                    if(s[i]=='|')
                        cnt1++;
                if(s[i]=='}')
                    {
                       ans*= cnt1;
                       cnt1=1;
                       flag1=0;
                    }
                if(flag2%2==1 && s[i]!=' ' && s[i-1]==' ')
                {
                    ans*=cnt2;
                    cnt2=1;
                }
                if(s[i]=='$'){
                    flag2++;
                    cnt2=1;
                }
                if(flag2%2==1 && s[i]==' ')
                {
                     cnt2++;
                }
    
                 if(ans>100000)
                      break;
            }
            if(ans>100000)
                 printf("doge
    ");
            else
                 printf("%lld
    ", ans);
        }
        return 0;
    }
    


    每天训练发现我比别人做的好慢,但是理解的更深刻,如果一开始学一个新知识点就搜模板,那么这样的人是走不远的,毕业之后带走的只有思维,什么荣誉,奖杯都已经不重要了。
  • 相关阅读:
    args4 1.4.12 编写一个程序,有序打印给定的两个有序数组(含有N 个int 值)中的所有公共元素,程序在最坏情况下所需的运行时间应该和N 成正比。
    优化斐波那契数列递归的计算
    Java中BO、DAO、DO、DTO、PO、POJO、VO的概念
    并查集算法Union-Find的思想、实现以及应用
    计算机网络中一些比较重要的概念
    [转]架构初探之架构的几种设计模式
    常见排序算法的思想以及稳定性分析
    数据库基础知识整理与复习总结
    Java面试之Java集合相关问题答案口述整理
    Java面试之Java基础问题答案口述整理
  • 原文地址:https://www.cnblogs.com/6bing/p/3931234.html
Copyright © 2011-2022 走看看