HDU 4891 The Great Pan(類比),hdu4891

來源:互聯網
上載者:User

HDU 4891 The Great Pan(類比),hdu4891

題目的意思還是比較好看懂的。注意以下幾點:

1.所有的{}與$$都是唯一匹配的啊,$$ $$這種情況按前兩個一組後兩個一組來算。

2.換行不會打破連續的空格。

3.{}與$$之間的不會有嵌套的形式。

4.中間計算過程有可能超int要用long long 來存。

The Great Pan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 485    Accepted Submission(s): 188


Problem DescriptionAs 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. 
InputInput 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. 
OutputFor each test case print the number of ways to understand this statement, or "doge" if your answer is more than  105
Sample Input
9I'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?}1Case $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
44doge6
 
AuthorFudan University 
Source2014 Multi-University Training Contest 3
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#define clear(A, X, SIZE) memset(A, X, sizeof(A[0]) * (SIZE))#define clearall(A, X) memset(A, X, sizeof(A))#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )#define min( x, y )  ( ((x) < (y)) ? (x) : (y) )#define LL long long#define maxn 1e5using namespace std;int main(){    int n;    LL ans,temp,cnt;    char c, x;    while(~scanf("%d",&n))    {        x=getchar();        while(x!='\n')        {            x=getchar();        }        bool flat1=false,flat2=false,flat=true;        ans=1;        temp=1;        while(n--)        {            while(1)            {                scanf("%c",&c);                if(c == '\n')                    break;                if(flat)                {                    if(ans>maxn || temp > maxn)                    {                        ans=maxn+10;                        flat=false;                        continue;                    }                    if(c=='{')                    {                        flat1=true;                        cnt=1;                    }                    else if(c=='}')                    {                        ans*=cnt;                        flat1=false;                    }                    else if(flat1&&c=='|')                    {                        cnt++;                    }                    else if(!flat2&&c=='$')                    {                        flat2=true;                        temp=1;                        cnt=1;                    }                    else if(flat2&&c=='$')                    {                        temp*=cnt;                        ans*=temp;                        flat2=false;                    }                    else if(flat2&&c==' ')                    {                        cnt++;                    }                    else if(flat2&&c!=' ')                    {                        temp*=cnt;                        cnt=1;                    }                }            }        }        if(ans>maxn)puts("doge");        else printf("%I64d\n",ans);    }    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.