zoukankan      html  css  js  c++  java
  • HDU 4891 The Great Pan (模拟)

    The Great Pan

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 463    Accepted Submission(s): 179



    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 ",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
     

    题意:

    题目给你n行文章,有两种情况,例如以下:

    1.对于{A|B|C|D|...},读出竖线的数量 x ,值为 x + 1

    2.对于$blah blah$。读出每小段连续的空格数y1、y2...,值为(y1 + 1) * (y2 + 1) * ....

    将以上求得的全部值相乘就可以。


    思路:

    模拟一遍就可以。

    注意点:

    1.注意数据相乘的积可能会超出int32位。甚至是long long的64位。

    例如以下例子:

    1
    $ a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a$

    一行共同拥有63个空。就会爆 long long。

    解决方式是当超出 10^5 时,将值改为 10^5 + 1 ,而且不再处理字符串,详见代码。


    /*************************************************************************
    	> File Name: 1005.cpp
    	> Author: Bslin
    	> Mail: Baoshenglin1994@gmail.com
    	> Created Time: 2014年07月29日 星期二 16时42分00秒
     ************************************************************************/
    
    #include <cstdio>
    #include <string.h>
    using namespace std;
    #define N 3050000
    
    char str[N];
    
    int main(int argc, char *argv[]) {
    	freopen("in.txt", "r", stdin);
    	int n, len, i, j, flagk, flag$, doge;
    	long long space, ans, tmp1, tmp2;
    	char nowk;
    	while(scanf("%d", &n) != EOF) {
    		ans = 1;
    		tmp1 = 1;  // 竖杠数
    		tmp2 = 1;  // 每段$$中的空格总乘积
    		space = 1; // 每小段空格数
    		flagk = flag$ = 0;  // 是否有"{"或"$"
    		doge = 0;
    		getchar();
    		for (i = 0; i < n; ++i) {
    			gets(str);
    			len = strlen(str);
    			if(doge) continue;
    			for (j = 0; j < len; ++j) {
    				if(str[j] == '{') {
    					flagk = 1;
    				} else if(str[j] == '}') {
    					ans = ans * tmp1;
    					tmp1 = 1;
    					flagk = 0;
    				} else if(str[j] == '$') {
    					if(flag$ == 0) {
    						flag$ = 1;
    					} else {
    						if(nowk == ' ') {
    							tmp2 = tmp2 * space;
    							if(tmp2 > 100000) tmp2 = 100001;   /////
    						}
    						ans = ans * tmp2;
    						tmp2 = 1;
    						space = 1;
    						flag$ = 0;
    					}
    				} else {
    					if(flagk) {
    						if(str[j] == '|') {
    							tmp1 ++;
    						}
    					}
    					if(flag$) {
    						if(str[j] == ' ') {
    							space ++;
    						} else {
    							tmp2 = tmp2 * space;
    							if(tmp2 > 100000) tmp2 = 100001;  /////
    							space = 1;
    						}
    					}
    				}
    				if(ans > 100000) doge = 1;
    				nowk = str[j];
    			}
    		}
    		if(doge) {
    			printf("doge
    ");
    		} else {
    			printf("%I64d
    ", ans);
    		}
    	}
    	return 0;
    }
    


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    autoresizing代码实现
    控制器的view的加载优先级
    iOS控制器的创建方式
    关于深复制和浅复制
    关于textField
    h5页面列表滚动加载数据
    数据库中存储过程和函数的区别
    Docker搭建Portainer可视化界面
    Docker部署springboot,从简单Eureka开始
    docker安装rabbitmq
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4633106.html
Copyright © 2011-2022 走看看