HDU4891-The Great Pan

题意:找出一共有多少中不同的问题的理解

思路:题目本身比较难读懂,但看明白之后就很简单了。其实可以先将所有字符串连接在一起,形成一个大字符串,然后再对整个字符串进行查找。

只要关心两种操作符就可以了。

1、{},只要将大括号里面的‘|‘的数量加上1,然后乘以ans

2、$$,将在内部遇到n个连续的空格就把ans乘以n + 1

最后注意ans在运算的过程中超int类型的范围

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

const int MAXN = 100000;

int n, cnt1, cnt2, flag;
long long ans;
string s, t;

int main() {
    while (scanf("%d", &n) != EOF) {
        getchar();
        s.clear();
        for (int i = 0; i < n; i++) {
            getline(std::cin, t);
            s += t;
        }
        ans = cnt1 = flag = 1;
        cnt2 = 2;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '{')
                flag = 0;
            else if (s[i] == '}') {
                flag = 1;
                ans *= cnt1;
                if (ans > MAXN)
                    break;
                cnt1 = 1;
            }
            else if (s[i] == '$') {
                flag = -flag;
            }
            if (flag == 0) {
                if (s[i] == '|')
                    cnt1++;
            }
            if (flag == -1) {
                if (s[i] == ' ' && s[i + 1] == ' ')
                    cnt2++;
                else if (s[i] == ' '){
                    ans *= cnt2;
                    cnt2 = 2;
                }
                if (ans > MAXN)
                    break;
            }
        } 

        if (ans > MAXN)
            printf("doge\n");
        else
            printf("%lld\n", ans);
    }
    return 0;
}

HDU4891-The Great Pan,布布扣,bubuko.com

时间: 2024-12-19 20:00:16

HDU4891-The Great Pan的相关文章

HDU4891 The Great Pan 暴力

题意:给你字符串,两种模式,每一种模式有相应规则的不同意思,问你这个字符串一共有多少意思 解题思路:合在一起两种模式暴力 解题代码: 1 // File Name: 1005.cpp 2 // Author: darkdream 3 // Created Time: 2014年07月29日 星期二 15时54分08秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9

hdu 6166 Senior Pan

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6166 题目: Senior Pan Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 245    Accepted Submission(s): 71 Problem Description Senior Pan fails i

Java实现3DES加密--及ANSI X9.8 Format标准 PIN PAN获取PIN BlOCK

1, 采用银联ANSI X9.8标准 PIN xor PAN获取PIN BlOCK 2, 采用3Des进行加密 参考: des和3Des加密算法实现 要点:因为3DES是对称加密算法,key是24位,当只有16位时,后8位取key的前8位 ANSI X9.8标准 PIN xor PAN获取PIN BlOCK (1) ANSI X9.8 Format(不带主账号信息) PIN(个人识别码 Personal Identity Number)总共有8个byte长度,分为两个部分;(类似数据包的格式)

hdu 4891 The Great Pan(模拟)

题目链接:hdu 4891 The Great Pan 题目大意:给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn+1), si表示连续的空格数. 2.{}中间,即 | 的个数+1. 解题思路:模拟. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1<<22

hdu 4891 The Great Pan (模拟)

为什么要开__int64 巨巨在哪~ # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int main () { __int64 count; int i,len,cot,cot1,j,flag,n; char a[1001][1030]; while(~scanf("%d",&n)) { getchar(); flag=0

ImageBox Control with Zoom/Pan Capability

Download source files - 10.8 Kb Download demo project - 6.81 Kb Introduction This control extends the capability of an ImageBox by including scrollbars to pan the image and a method for zooming the size of the image. My goal here is to show you two t

hdu 4891 The Great Pan

#include<stdio.h> #include<string> #include<string.h> #include<iostream> using namespace std; string s; char tmp[2000000]; int main() { int snum;//s int lnum;//{ int n; int i,j; __int64 ans; while(scanf("%d",&n)!=EOF)

HDU 4891 The Great Pan (字符串处理)

题目链接:HDU 4891 The Great Pan 求一串字符有多少种不同的意思,当中关心'{','}'之间的'|'. 和'$','$'之间的空格,连续N个空格算N+1种. AC代码: #include<stdio.h> #include<string> #include<string.h> using namespace std; char s[2*1024*1024+10]; string ss; int cnt; int find(int x,int y) {

ZOJ 3762 Pan&#39;s Labyrinth 计算几何

题意:给出一系列的坐标,要求出这些坐标中组成的三角形中最大的高是多少 下列两个假设必然有一个成立 1.点C是所有点中距离点A最远的 2.点C是所有点中距离点B最远的 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> using namespace std; struct point { double x,y; }p[5