HDU--4891--The Great Pan--暴力搜尋

來源:互聯網
上載者:User

標籤:des   style   color   java   os   strong   檔案   io   

The Great PanTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 827    Accepted Submission(s): 292

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 than105. 
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
 題意:如果是{},求其中的 “ | ” 的個數,然後加一乘到總和裡面,如果是 $ $ ,求其中空格,連續的n個空格有n+1種方式,$ $ 中的空格段之間的計算也是直接相乘,然後乘到總和裡面

體驗過什麼叫WA到死嗎?-.-!不羅嗦了,注意的就是其中的方式總量是會超過int範圍的,所以要及時判斷出來,還有一個,也就是把我卡了半天的,就是判斷檔案大小,每次輸入最大檔案是1024KB,一個字元是1B,所以每次輸入的字串長度都是百萬++的   T.T 所果斷開了500W的才過


代碼太簡單,所以不注釋了


#include <iostream>#include <cstdio>#include <cstring>using namespace std;char str[5000000];int main (void){    int n,i,j,k,l;    __int64 num,s;    while(~scanf("%d%*c",&n))    {        num=1;        k=0;        s=0;        while(n--&&gets(str))        {            l=strlen(str);            if(num>100000)continue;            for(i=0;i<l;i++)            {                if(str[i]==‘$‘||str[i]==‘{‘||str[i]==‘}‘)                {                    if(k!=0)                    {                        if(num*(s+1)>100000)                        {                            num=100001;                            break;                        }                        num*=s+1;                        s=0;                        k=0;                    }                    else if(str[i]==‘$‘)k=1;                    else k=2;                }else if(k==1)                {                    if(str[i]==‘ ‘)                    {                        s++;                        if(s>=100000)                        {                            num=100001;                            break;                        }                    }                    else                    {                        if(num*(s+1)>100000)                        {                            num=100001;                            break;                        }                        num*=s+1;                        s=0;                    }                }else if(k==2)                {                    if(str[i]==‘|‘)                    {                        s++;                        if(s>=100000)                        {                            num=100001;                            break;                        }                    }                }            }        }        if(num>100000)puts("doge");        else printf("%I64d\n",num);    }    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.