hdu 6144 Arithmetic of Bomb

Arithmetic of Bomb

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 151    Accepted Submission(s): 108

Problem Description

众所周知,度度熊非常喜欢数字。

它最近在学习小学算术,第一次发现这个世界上居然存在两位数,三位数……甚至N位数!

但是这回的算术题可并不简单,由于含有表示bomb的#号,度度熊称之为 Arithmetic of Bomb。

Bomb Number中的bomb,也就是#号,会展开一些数字,这会导致最终展开的数字超出了度度熊所能理解的范畴。比如”(1)#(3)”表示”1”出现了3次,将会被展开为”111”,

同理,”(12)#(2)4(2)#(3)”将会被展开为”12124222”。

为了方便理解,下面给出了Bomb Number的BNF表示。

```
<bomb number> := <bomb term> | <bomb number> <bomb term>
<bomb term> := <number> | ‘(‘ <number> ‘)‘ ‘#‘ ‘(‘ <non-zero-digit> ‘)‘
<number> := <digit> | <digit> <number>
<digit> := ‘0‘ | ‘1‘ | ‘2‘ | ‘3‘ | ‘4‘ | ‘5‘ | ‘6‘ | ‘7‘ | ‘8‘ | ‘9‘
<non-zero-digit> := ‘1‘ | ‘2‘ | ‘3‘ | ‘4‘ | ‘5‘ | ‘6‘ | ‘7‘ | ‘8‘ | ‘9‘
```

请将Bomb Number中所有的#号展开,由于数字可能很长,结果对 1 000 000 007 取模。

Input

第一行为T,表示输入数据组数。

每组数据包含一个Bomb Expression。

- 1≤T≤100

- 1≤length(Bomb Number)≤1000

Output

对每组数据输出表达式的结果,结果对 1 000 000 007 取模。

Sample Input

4

1

(1)#(3)

(12)#(2)4(2)#(3)

(12)#(5)

Sample Output

1

111

12124222

212121205

Source

2017百度之星程序设计大赛 - 复赛

Recommend

We have carefully selected several similar problems for you:  6149 6148 6147 6146 6145

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int T,i,len;
long long ans;
char ch[100005];
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",&ch);

        ans=0;
        for(i=0;ch[i];i++)
        {
            if (isdigit(ch[i])) {ans=(ans*10+ch[i]-‘0‘)%mod; continue;}
            long long pos=1,k=0;
            for(++i;ch[i]!=‘)‘;i++)
            {
                k=(k*10+ch[i]-‘0‘)%mod;
                pos=pos*10%mod;
            }
            for(int j=1;j<=ch[i+3]-‘0‘;j++)
                ans=(ans*pos+k)%mod;
           i+=4;
        }
        printf("%lld\n",ans);
    }
    return 0;
}
时间: 2024-07-29 21:16:40

hdu 6144 Arithmetic of Bomb的相关文章

2017&quot;百度之星&quot;程序设计大赛 - 复赛1001&amp;&amp;HDU 6144 Arithmetic of Bomb【java大模拟】

Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 129    Accepted Submission(s): 94 Problem Description 众所周知,度度熊非常喜欢数字. 它最近在学习小学算术,第一次发现这个世界上居然存在两位数,三位数……甚至N位数! 但是这回的算术题可并不简单,由于

[HDOJ6144] Arithmetic of Bomb(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6144 XJB模拟一下就行,反正最多重复⑨次. 非要说用上什么数学原理的话,大概就是(a+b)%mod = (a%mod)+(b%mod)%mod,(a*b)%mod...吧 1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃

hdu 5400 Arithmetic Sequence

click here~~ ***Arithmetic Sequence*** Problem Description A sequence b1,b2,?,bn are called (d1,d2)-arithmetic sequence if and only if there exist i(1≤i≤n) such that for every j(1≤j<i),bj+1=bj+d1 and for every j(i≤j<n),bj+1=bj+d2. Teacher Mai has a

hdu 5400 Arithmetic Sequence(模拟)

Problem Description A sequence b1,b2,?,bn are called (d1,d2)-arithmetic sequence if and only if there exist i(1≤i≤n) such that for every j(1≤j<i),bj+1=bj+d1 and for every j(i≤j<n),bj+1=bj+d2. Teacher Mai has a sequence a1,a2,?,an. He wants to know h

HDU 5400 Arithmetic Sequence (2015年多校比赛第9场)

1.题目描述:点击打开链接 2.解题思路:本题利用扫描法解决.根据题意描述,[L,i)和[i,R)区间都构成了等差数列,因此可以实现用L[i],R[i]来维护从i开始向左向右可以延伸的最远长度,如果d1和d2不等,那么答案就是L[i]*R[i]求和,否则就是R[i]求和. 3.代码: //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<algorit

hdu(5400)——Arithmetic Sequence(想法题)

题意: 首先,现在给出三个数字n,d1,d2.然后第二行给出n个数字. 然后题目要求的是求这个序列中有几个区间满足一下条件之一: 1)这个区间是一个等差数列,且公差为d1或d2: 2)若一个区间为[l,r],那么有l<=i<=r,使得[l,i]范围内是公差为d1的等差数列,[i,r]区间内是公差为d2的等差数列. *注意,这里单个数字一定是满足等差数列的.而且这里数字最好都使用__int64来保存,因为这个原因我们队WA了好几次. 思路: 这里我设了头和尾两个指针,分别用l和r表示. 我用de

2017年百度之星

初赛A 小C的倍数问题 p-1因子个数 #include <bits/stdc++.h> const long long mod = 1e9+7; const double ex = 1e-10; #define inf 0x3f3f3f3f using namespace std; int main() { int T; cin >> T; while (T--){ long long x; cin >> x; long long ans = 0; for (long

HDU 3622 Bomb Game(二分+2-SAT)

Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5396    Accepted Submission(s): 1925 Problem Description Robbie is playing an interesting computer game. The game field is an unbounde

hdu 3555 Bomb(数位dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:就是给你一个数n,判断从0到n有多少个数含有数字49...... 是不是觉得跟hdu2089很相似呀... 思路:跟hdu2089一样的,注意给出的数比较大,所以这儿用__int64  .... code: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm&