题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4891
----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
2014 Multi-University Training Contest 3 签到题;
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 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
Source
2014 Multi-University Training Contest 3
代码如下:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 1024*1024+17
char s[maxn], ss[maxn];
int main()
{
int n;
int i, j, k;
while(~scanf("%d",&n))
{
getchar();
memset(s,'\0',sizeof(s));
int len;
for(i = 0; i < n; i++)
{
gets(ss);
len = strlen(ss);
strcat(s,ss);
}
int mark=0;
int c1 = 0, c2 = 0;
__int64 sum1 = 1, sum2 = 1,sum = 0;
int LEN = strlen(s);
for(i = 0; i < LEN; i++)
{
if(s[i] == '{')
{
c1 = 0;
for(i+=1; ; i++)
{
if(s[i] == '|')
{
c1++;
}
else if(s[i] == '}')
break;
}
sum1*=(c1+1);
if(sum1 > 100000)
{
mark = 1;
break;
}
}
if(s[i] == '$')
{
c2 = 0;
for(i+=1;;i++)
{
c2 = 0;
if(s[i] == ' ')
{
c2++;
for(i+=1;;i++)
{
if(s[i] == ' ')
c2++;
else
break;
}
sum2*=(c2+1);
if(sum2 > 100000)
{
mark = 1;
break;
}
}
if(s[i] == '$')
break;
}
}
}
if(mark)
{
printf("doge\n");
continue;
}
sum = sum1*sum2;
if(sum <= 100000)
printf("%I64d\n",sum);
else
printf("doge\n");
}
return 0;
}