Codeforces Round #265 (Div. 2) E
这题说的是给了数字的字符串 然后有n种的操作没次将一个数字替换成另一个字符串,求出最后形成的字符串的 数字是多大,我们可以逆向的将每个数推出来,计算出他的值和位数记住位数用10的k次方来记 1位就是10 2位就是100,这样是为了防止当位数很大的时候存不下这样可以直接的进行mod操作
#include <iostream>
#include <cstdio>
#include <string.h>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int max_n=;
const ll mod= ;
struct point{
ll val,loc;
}digit[];
char str[max_n];
vector<int> F[max_n];
char S[max_n];
int n;
int main()
{
while(scanf("%s",str)==){
for(int i=; i<; ++i)
digit[i].loc=,digit[i].val=i;
scanf("%d",&n);
for(int i=; i<n; i++){
F[i].clear();
scanf("%s",S);
F[i].push_back(S[]-'');
int len=strlen(S);
for(int j=; j<len; ++j)
F[i].push_back(S[j]-'');
}
for(int i =n-; i>=; --i )
{
ll val=,loc=;
int L =F[i].size();
for(int k=L-; k>; --k){
int t =F[i][k];
val=(val+loc*digit[t].val)%mod;
loc=(loc*digit[t].loc)%mod;
}
digit[F[i][]].loc=loc;
digit[F[i][]].val=val;
}
ll ans=,loc=;
int L =strlen(str);
for(int i=L-; i>=; --i){
ll t= str[i]-'';
ans=(ans+digit[t].val*loc)%mod;
loc=(loc*digit[t].loc)%mod;
}
printf("%I64d\n",ans);
}
return ;
}
Codeforces Round #265 (Div. 2) E的更多相关文章
- Codeforces Round #265 (Div. 1) C. Substitutes in Number dp
题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断
http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...
- Codeforces Round #265 (Div. 2)
http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...
- Codeforces Round #265 (Div. 2) B. Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others ...
- Codeforces Round #265 (Div. 1)
D. World of Darkraft - 2 time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- PHP-002
PHP URL重写 怎样在IIS环境下配置Rewrite规则_百度经验 http://jingyan.baidu.com/article/c33e3f485a7c74ea15cbb50e.html W ...
- 09python之运算
运算 算数运算: 两个数相除,得到商和余数的数组的内置方法 数据.__divmod__() 场景 数据库共99条数据,每个页面10条数据,需要多少个页面 >>> a = 98 ...
- eclipse中tomcat能正常启动,在浏览器中不能打开问题
问题原因:没有在eclipse中tomcat的server location设置到tomcat的安装目录. 解决办法:1.选择server点击右键,选择Open选项,然后在server locatio ...
- pow()
pow() 如果接收两个参数,如 pow(x, y),则结果相当于 x**y,也就是 x 的 y 次方pow() 如果接收三个参数,如 pow(x, y, z),则结果相当于 (x**y) % z,也 ...
- java运行显示“找不到或无法加载主类”的解决办法(linux)
要是配置文件的路径问题.打开终端,输入vi ~/.bashrc添加如下代码即可. # set Java environmentJAVA_HOME=/usr/local/java/jdk1.8.0PAT ...
- Android 基于帧布局实现一个进度条 FrameLayout+ProgressBar
在FrameLayout中添加一个ProgressBar居中 <ProgressBar android:layout_gravity="center" android:id= ...
- php 数据库练习之租房子
题目: 示例图 本次只做图4这个表,因为之前的都已做过 自己在mydb数据库建了一个house表 如图: 自己做的代码: <!DOCTYPE html PUBLIC "-//W3C// ...
- RxJava && Agera 从源码简要分析基本调用流程(2)
版权声明:本文由晋中望原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/124 来源:腾云阁 https://www.qclo ...
- Excel 2010 如何在Excel的单元格中加入下拉选项
http://jingyan.baidu.com/article/03b2f78c4ba8a05ea237ae95.html 第一步:打开excel文档,选中需加入下拉选项的单元格. 第二步:点击 ...
- java EE ME SE有什么关系
1. Java SE(Java Platform,Standard Edition).Java SE 以前称为 J2SE.它允许开发和部署在桌面.服务器.嵌入式环境和实时环境中使用的 Java 应用程 ...