您的位置:首页 > 其它

HDU4891:The Great Pan

2014-07-30 17:01 239 查看
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 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




题意:
理解方法最少油一种,ans = 1
1.{}内的|个数为n,那么就是ans*=(n+1)
2.$$内的连续空格独立理解,每有一个连续的n个空格,ans*=(n+1)
3.输出理解方案数,超过100000输出doge
4.{},$$不会有嵌套,所以你也不需要去钻牛角尖考虑太多,要注意中间过程可能超出int型,我在这里贡献了n次WA

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

char str[5000000],s[5000000];
int main()
{
    int n,i,j;
    int cnt1,cnt2,flag1,flag2,len;
    __int64 sum;
    while(scanf("%d",&n)!=EOF)
    {
        gets(str);
        len = 0;
        for(i = 0; i<n; i++)
        {
            gets(str);
            int l = strlen(str);
            for(j = 0; j<l; j++)
            {
                s[len] = str[j];
                len++;
            }
        }
        flag1 = flag2  = cnt1 = cnt2 = 0;
        sum = 1;
        for(i = 0; i<len; i++)
        {
            if(s[i] == '{')
                flag1 = 1;
            else if(flag1 && s[i] == '|')
                cnt1++;
            else if(flag1 && s[i] == '}')
            {
                flag1 = 0;
                sum*=(cnt1+1);
                cnt1 = 0;
            }
            else if(s[i] == '$' && flag2 == 0)
                flag2 = 1;
            else if(s[i] == '$' && flag2 == 1)
            {
                sum = sum*(cnt2+1);
                cnt2 = 0;
                flag2 = 0;
            }
            else if(flag2 && s[i] == ' ')
                cnt2++;
            else if(flag2 && s[i] != ' ' && s[i]!='$')
            {
                sum = sum*(cnt2+1);
                cnt2 = 0;
            }
            if(sum>100000)
                break;
        }
        if(sum>100000)
            printf("doge\n");
        else
            printf("%I64d\n",sum);
    }

    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: