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

    题意:给定一个文章,问你有多少种读法,计算方法有两种,如果在$中,如果有多个空格就算n+1,如果是一个就算2的次方,如果在{}中,

    那么就是把每个空格数乘起来。

    析:直接模拟,每次计算一行,注意上一行最后有空格,下面第一个也是,要全部算上。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #define debug puts("+++++")
    //#include <tr1/unordered_map>
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    //using namespace std :: tr1;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const LL LNF = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e3 + 5;
    const LL mod = 1e9 + 7;
    const int N = 1e6 + 5;
    const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
    const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
    const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    inline LL gcd(LL a, LL b){  return b == 0 ? a : gcd(b, a%b); }
    inline int gcd(int a, int b){  return b == 0 ? a : gcd(b, a%b); }
    inline int lcm(int a, int b){  return a * b / gcd(a, b); }
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    inline LL Min(LL a, LL b){ return a < b ? a : b; }
    inline LL Max(LL a, LL b){ return a > b ? a : b; }
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    char s[1000000];
    const int ttt = 100000;
    int main(){
        while(scanf("%d", &n) == 1){
            getchar();
            LL ans = 1;
            bool ok = false;
            bool is = false;
            int cnt1 = 0, cnt2 = 0;
            bool ok1 = false;
            bool ok2 = false;
            while(n--){
                gets(s);
                for(int i = 0; s[i]; ++i){
                    if(s[i] == '$' && !ok1) ok1 = true;
                    else if(s[i] == '{') ok2 = true;
                    else if(s[i] == '$'){
                        ok1 = false;
                        if(!cnt1)  continue;
                        if(cnt1 == 1){
                            if(ans * 2LL > ttt) ok = true;
                            else ans *= 2LL;
                        }
                        else {
                            if(ans * (cnt1+1) > ttt)  ok = true;
                            else  ans *= (cnt1 + 1);
                        }
                        cnt1 = 0;
                    }
                    else if(s[i] == '}'){
                        ok2 = false;
                        if(ans * (cnt2+1) > ttt) ok = true;
                        else ans *= cnt2 + 1;
                        cnt2 = 0;
                    }
                    else if(s[i] == '|' && ok2)  ++cnt2;
                    else if(s[i] == ' ' && ok1)  ++cnt1;
                    else{
                        if(ok1 && cnt1){
                            if(cnt1 == 1){
                                if(ans * 2LL > ttt) ok = true;
                                else ans *= 2LL;
                            }
                            else {
                                if(ans * (cnt1+1) > ttt)  ok = true;
                                else  ans *= (cnt1 + 1);
                            }
                            cnt1 = 0;
                        }
                    }
                }
            }
            if(ok)  puts("doge");
            else printf("%I64d
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    非标准的xml解析器的C++实现:二、解析器的基本构造:语法表
    非标准的xml解析器的C++实现:一、思考基本数据结构的设计
    lua5.4 beta中的to-be-closed变量的用法
    lua table与json的之间的互相转换高性能c++实现
    lua多线程共享数据的解决方案
    winsock完成端口套接字重用注意事项
    Less相关的用法以及Vue2.0 中如何使用Less
    1:MUI选择器组件抛出“n.getSelectedItem is not a function”异常的解决办法 2:mui三级联动 3:移动端关闭虚拟键盘
    redux状态管理和react-redux的结合使用
    初步学习React Router 4.0
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/6014124.html
Copyright © 2011-2022 走看看