The Great Pan

理解模糊编程问题陈述的多种可能性
编程竞赛爱好者Waybl在参加Inventing Crappy Problems Contest时遭遇了模糊问题陈述的挑战。通过与Great Pan的交流,他了解到解析问题陈述有多重解读方式。本文探讨了如何计算给定问题陈述的多种理解方法,包括处理特殊标记如花括号、美元符号等,以及连续空格的解释多样性。
                                         The Great Pan
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

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

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\n",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
 
 
D - The Great Pan
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

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

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\n",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>

    char a[500000];

    int main()
    {
        long long  i,n,flag,ans,sum,flag2,num;

        while(scanf("%lld%*c",&n)!=EOF)
        {
            memset(a,0,sizeof(a));

            for(i=0;i<n;i++)
            {
                gets(a+strlen(a));
            }
            //puts(a);

            flag=0;
            flag2=0;
            num=1;
            ans=1;

            for(i=0; a[i]!='\n'; i++)
            {
                if(a[i]=='{')
                {
                    flag=1;
                    sum=1;
                }
                if(a[i]=='}')
                {
                     flag=0;
                     ans*=sum;
                     	//printf("1%d* ", ans );
                }
                if(flag==1)
                {
                    if(a[i]=='|')
                        sum++;
                }

                if( flag2==1 && a[i]!=' ' && a[i-1]==' ')
                {
                    ans*=num;
                    	//printf("2%d* ", ans );
                    num=1;
                }

                if(a[i]=='$')
                {
                    if(flag2==0)
                        flag2=1;
                    else
                        flag2=0;
                    num=1;
                }
                if(flag2==1&&a[i]==' ')
                    num++;
                if(ans>100000)
                    break;
            }
            if(ans>100000)
                puts("doge");
            else
                 printf("%lld\n",ans);
        }
        return 0;
    }

 

 

转载于:https://www.cnblogs.com/yspworld/p/3878222.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值