Codeforces 464C Substitutes in Number 同余定理+模拟
来源:互联网 发布:手机测量尺寸软件 编辑:程序博客网 时间:2024/05/21 09:09
题目链接:点击打开链接
题意:
给定一串数字
下面有n个操作
每行格式形如 d->t
d为一位数字,t为任意长度的数字。
t的长度和不超过100000
问:最后的结果%1e9+7
思路:
首先我们可以得到一个结论:
同余定理使用后不能再修改数字。
那么为了让同余定理能够使用,我们倒序处理每个数字,这样就能保证能够使用同余定理。
记录每个数字实际代表的数字和实际对应的位数。
然后倒序处理上来即可。
#include <stdio.h>#include <string.h>#include <iostream>#include <math.h>#include <queue>#include <set>#include <algorithm>using namespace std;#define N 100005#define M 100005typedef long long ll;const ll mod = 1000000007;char s[N], t[N];struct node{int d;string s;}a[N];ll v[10], wei[10], d[M];ll W(ll x){if(x==0)return 1LL;ll ans = 0;while(x){x/=10; ans++;}return ans;}int n;void solve(){scanf("%d",&n); getchar();for(int i = 1; i <= n; i++) {scanf("%d->", &a[i].d);gets(t);a[i].s = t;}for(int i = 0; i < 10; i++) {v[i] = i , wei[i] = 10LL;}for(int i = n; i >= 1; i--){ll now = 0;ll len = (ll)a[i].s.length();if(len == 0) { v[ a[i].d ] = 0; wei[ a[i].d ] = 1; continue;}ll X = 1;for(ll j = 0; j < len; j++){now *= wei[a[i].s[j]-'0'];now += v[ a[i].s[j]-'0'];X = (X * wei[ a[i].s[j]-'0' ])%mod;now %= mod;}v[ a[i].d ] = now;wei[a[i].d] = X;}ll ans = 0;for(int i = 0; s[i]; i++) {ans *= wei[ s[i]-'0' ];ans += v[ s[i]-'0' ];ans %= mod;}cout<<ans<<endl;}int main(){while(gets(s))solve();return 0;}/*12312312->0012312313->22222->00->710000000080*/
0 0
- Codeforces 464C Substitutes in Number 同余定理+模拟
- codeforces 464C Substitutes in Number
- Codeforces 464C Substitutes in Number
- 【DP】 codeforces 464C Substitutes in Number
- Codeforces 464 C. Substitutes in Number
- codeforces 464C Substitutes in Number dp
- codeforces #464C Substitutes in Number
- Codeforces 464C Substitutes in Number(高效+快速幂)
- Codeforces 464 C. Substitutes in Number 动态规划法题解
- HDoj1212Big Number(同余定理)
- Codeforces#427C Checkposts 【Tarjan求scc 】+【同余定理】
- codeforces-827C-树状数组,同余定理
- HDU1212 Big Number 【同余定理】
- HDU 1212 Big Number(同余定理)
- hdoj 1212 Big Number 【同余定理】
- HDOJ 1212 Big Number【同余定理】
- Codeforces Round #265 (Div. 2)E. Substitutes in Number(数学)
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
- 从在浏览器输入URL到页面加载完成所发生的
- Linux下分割合并文件
- 最长连续公共子序列
- poj 2769 Reduced ID Numbers
- jsp中include的两种形式
- Codeforces 464C Substitutes in Number 同余定理+模拟
- 强大的QDataStream
- [English]形容词和名词
- 关于字符串中回文子串的思考
- Flow Control in TCP(tcp的流量控制实现)
- Reading comprehension (BestCoder Round #8) (hdoj 4990)
- JSON解析的时候遇到NSNull
- 过桥问题(美团2014笔试题)
- hdf4