题目链接: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