[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 ┛┗┛┗┛┃
 11 ┓┏┓┏┓┃
 12 ┛┗┛┗┛┃
 13 ┓┏┓┏┓┃
 14 ┃┃┃┃┃┃
 15 ┻┻┻┻┻┻
 16 */
 17 #include <bits/stdc++.h>
 18 using namespace std;
 19 #define fr first
 20 #define sc second
 21 #define cl clear
 22 #define BUG puts("here!!!")
 23 #define W(a) while(a--)
 24 #define pb(a) push_back(a)
 25 #define Rint(a) scanf("%d", &a)
 26 #define Rll(a) scanf("%I64d", &a)
 27 #define Rs(a) scanf("%s", a)
 28 #define Cin(a) cin >> a
 29 #define FRead() freopen("in", "r", stdin)
 30 #define FWrite() freopen("out", "w", stdout)
 31 #define Rep(i, len) for(int i = 0; i < (len); i++)
 32 #define For(i, a, len) for(int i = (a); i < (len); i++)
 33 #define Cls(a) memset((a), 0, sizeof(a))
 34 #define Clr(a, x) memset((a), (x), sizeof(a))
 35 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
 36 #define lrt rt << 1
 37 #define rrt rt << 1 | 1
 38 #define pi 3.14159265359
 39 #define RT return
 40 #define lowbit(x) x & (-x)
 41 #define onenum(x) __builtin_popcount(x)
 42 typedef long long LL;
 43 typedef long double LD;
 44 typedef unsigned long long ULL;
 45 typedef pair<int, int> pii;
 46 typedef pair<string, int> psi;
 47 typedef pair<LL, LL> pll;
 48 typedef map<string, int> msi;
 49 typedef vector<int> vi;
 50 typedef vector<LL> vl;
 51 typedef vector<vl> vvl;
 52 typedef vector<bool> vb;
 53
 54 const LL mod = 1e9+7;
 55 const int maxn = 1001000;
 56 char s[maxn];
 57 int n;
 58 int digit[maxn];
 59 LL ret;
 60
 61 LL mul(LL x, LL n) {
 62     LL ret = 1;
 63     while(n) {
 64         if(n & 1) ret = ret * x % mod;
 65         x = x * x % mod;
 66         n >>= 1;
 67     }
 68     return ret;
 69 }
 70
 71 signed main() {
 72     // FRead();
 73     int T;
 74     Rint(T);
 75     W(T) {
 76         Rs(s+1); n = strlen(s+1);
 77         ret = 0;
 78         int i = 1;
 79         while(i <= n) {
 80             if(s[i] == ‘(‘) {
 81                 int j = i + 1, k = 0;
 82                 LL x = 0;
 83                 while(s[j] != ‘)‘) {
 84                     digit[++k] = s[j] - ‘0‘; j++;
 85                 }
 86                 j++; j += 2;
 87                 while(s[j] != ‘)‘) {
 88                     x = x * 10 + s[j] - ‘0‘;
 89                     j++;
 90                 }
 91                 i = j + 1;
 92                 LL y = k * x;
 93                 For(j, k+1, y+1) digit[j] = digit[(j-1)%k+1];
 94                 For(j, 1, y+1) {
 95                     ret = ret * 10 % mod;
 96                     ret += digit[j];
 97                     ret %= mod;
 98                 }
 99             }
100             else {
101                 int j = i, k = 0;
102                 while(s[j] != ‘(‘ && s[j]) {
103                     digit[++k] = s[j++] - ‘0‘;
104                 }
105                 i = j;
106                 For(j, 1, k+1) {
107                     ret = ret * 10 % mod;
108                     ret += digit[j];
109                     ret %= mod;
110                 }
111             }
112         }
113         printf("%I64d\n", ret);
114     }
115     RT 0;
116 }
时间: 2024-11-05 01:46:19

[HDOJ6144] 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位数! 但是这回的算术题可并不简单,由于

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位数! 但是这回的算术题可并不简单,由

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

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

Defuse the Bomb——ZOJ3938模拟

Defuse the Bomb Time Limit: 2 Seconds      Memory Limit: 65536 KB The bomb is about to explode! Please defuse it as soon as possible! There is a display showing a number from 1 to 4 on the bomb. Besides this, there are 4 buttons under the display. Ea

【模拟】Codeforces 699B One Bomb

题目链接: http://codeforces.com/problemset/problem/699/B 题目大意: N*M的图,*代表墙.代表空地.问能否在任意位置(可以是墙上)放一枚炸弹(能炸所在行和列),把所有的墙都炸掉.输出答案(不唯一). 题目思路: [模拟] N2预处理出每一行能炸多少墙,每一列能炸多少墙.再N2枚举放炸弹的位置看能炸掉的墙数目是否等于总数.注意如果炸弹位置上有墙要-1. 1 // 2 //by coolxxx 3 ////<bits/stdc++.h> 4 #in

PAT甲题题解-1088. Rational Arithmetic (20)-模拟分数计算

输入为两个分数,让你计算+,-,*,\四种结果,并且输出对应的式子,分数要按带分数的格式k a/b输出如果为负数,则带分数两边要有括号如果除数为0,则式子中的结果输出Inf模拟题最好自己动手实现,考验细节处理,其它没啥好说的. #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; long long numerato

hdu 4930 Fighting the Landlords (模拟)

Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 160    Accepted Submission(s): 52 Problem Description Fighting the Landlords is a card game which has been a heat for ye

HDU 4930 Fighting the Landlords(扯淡模拟题)

Fighting the Landlords 大意: 斗地主....   分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. 给你8种组合:1.