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 ...
随机推荐
- Python 处理命令行参数
optparse模块用于从命令行直接读取参数,用法基本与 argparse模块 一致,如下: #!/usr/bin/env python #-*- coding:utf-8 -*- from optp ...
- kubectl get 输出格式
常见的输出格式有: * custom-columns=<spec> # 根据自定义列名进行输出,逗号分隔 * custom-columns-file=<filename> # ...
- js遍历商品编码
function bathAuditGoods(state) { var selections = $("#deliveryGrid").datagrid('getSelectio ...
- canvas二:绘制圆和其他曲线
1.绘制圆 绘制圆是canvas里面不可缺少的功课,而且绘制圆在canvas中的用处很多,好嘞,开扯 绘制圆需要用到arc这个方法: arc(X坐标,Y坐标,半径,起始弧度,结束弧度,旋转方向): 弧 ...
- 是否可以从一个static(静态)方法内部调用非static(非静态)方法?
不可以.static方法调用时不需要创建对象(可直接调用),当一个static方法被调用时,可能还没有创建任何实例对象,也就不可能调用非静态方法.
- <转>KMP算法详解
看了好久的KMP算法,都一直没有看明白,直到看到了这篇博客http://www.tuicool.com/articles/e2Qbyyf让我瞬间顿悟. 如果你看不懂 KMP 算法,那就看一看这篇文章 ...
- iGson
头文件 #import <Foundation/Foundation.h> #import <objc/runtime.h> #import "NSString+Ut ...
- java基础---->java中字符编码问题(一)
这里面对java中的字符编码做一个总结,毕竟在项目中会经常遇到这个问题.爱不爱都可以,我怎样都依你,连借口我都帮你寻. 文件的编码格式 一.关于中文的二进制字节问题 public static Str ...
- MQTT协议笔记之连接和心跳
前言 本篇会把连接(CONNECT).心跳(PINGREQ/PINGRESP).确认(CONNACK).断开连接(DISCONNECT)和在一起. CONNECT 像前面所说,MQTT有关字符串部分采 ...
- Mysql limit offset用法举例
转自:http://blog.csdn.net/iastro/article/details/53037600 Mysql limit offset示例 例1,假设数据库表student存在13条数据 ...