您的位置:首页 > 其它

hdu 4891 跳出循环之后可能存在还为处理的值,字符串的个数可能超过long long

2014-07-30 09:32 387 查看


The Great Pan

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 528 Accepted Submission(s): 199



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


Author

Fudan University

Source

2014 Multi-University Training Contest 3

/***********************************************\
|Author: YMC
|Created Time: 2014-7-29 13:08:14
|File Name: 1005.cpp
|Description:
\***********************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#define L(rt) (rt<<1)
#define R(rt) (rt<<1|1)
#define mset(l,n) memset(l,n,sizeof(l))
#define rep(i,n) for(int i=0;i<n;++i)
#define maxx(a) memset(a, 0x3f, sizeof(a))
#define zero(a) memset(a, 0, sizeof(a))
#define srep(i,n) for(int i = 1;i <= n;i ++)
#define MP make_pair
const int inf=0x3f3f3f3f ;
const double eps=1e-8 ;
const double pi=acos (-1.0);
typedef long long ll;

using namespace std;
string s;
int n;
int main() {
//freopen("input.txt","r",stdin);
bool fg1,fg2,fg;
long long ans;
int num1,num2;
while(cin>>n){
getline(cin,s);
fg1 = false;fg2 = false;fg = true;
ans = 1;
rep(i,n){
getline(cin,s);
if(!fg) continue;
//int len =s.length();
rep(j,s.length()){
if(!fg) break;
if(ans > 100000){
fg = false;
break;
}
if(fg1){
if(s[j] == '}'){
ans *= num1 + 1;
fg1 = false;
continue;
}
if(s[j] == '|'){
num1++;
if(num1 > 100000){
fg = false;
break;
}
continue;
}else{
continue;
}
}
if(fg2){
if(s[j] == '$'){
ans *= num2;
num2 = 1;
fg2 = false;
continue;
}
if(s[j] == ' '){
num2++;
if(num2 > 100000){
fg = false;
break;
}
} else {
ans *= num2;
num2 = 1;
}
if(ans > 100000){
fg = false;
fg2 = true;
continue;
}
}
if(s[j] == '{'){
num1 = 0;
fg1 = true;
}
if(s[j] == '$'){
num2 = 1;
fg2 = true;
}
}
}
if(ans > 100000) fg = false;<span style="white-space:pre">	</span>//这个地方没写就错了。
if(!fg){
cout<<"doge"<<endl;
}else {
cout<<ans<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: