CF464C-Substitutes in Number

题意

开始给出一个长为\(n\)的数字串,有\(m\)次操作按顺序执行,每次把当前数字串中的某一个数码替换成一个数字串\(t\)(可以为空或多位),最后问操作结束后的数字串十进制下模\(10^9+7\)的值。

\(n,m,\sum t\le 10^5\)

分析

这题很妙啊!

直接做肯定是不行的,因为替换的时候长度没有保证。遇到这种前面对后面有影响的问题,可以考虑反过来做。

如果能够求出所有操作结束后,每个数码代表什么数字串,那么直接代入开始的串就可以得到答案了!

对于每一种数码(0-9)保存到现在为止它代表的数字串模\(10^9+7\)的值,以及它的长度(可以直接用\(10^k\)来表示)。从后往前操作,每一次会改动一种数码,就把改后串用当前的数码状态计算一个当前值出来,代表这个数码当前代表了什么值。

其实就是一个从后往前计算回代的过程。这种from the other end的思路是很奇妙的。

代码

#include<cstdio>
#include<cstring>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
typedef long long giant;
const int maxn=1e5+10;
const int q=1e9+7;
inline int Plus(int x,int y) {return ((giant)x+(giant)y)%q;}
inline int Multi(int x,int y) {return (giant)x*y%q;}
char s[maxn];
pair<int,string> c[maxn];
pair<int,int> a[10],b[10];
int main() {
#ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
#endif
    int n;
    scanf("%s%d",s+1,&n);
    for (int i=1;i<=n;++i) {
        static char t[maxn];
        int d;
        scanf("%s",t);
        c[i]=make_pair(t[0]-'0',t+3);
    }
    for (int i=0;i<10;++i) a[i]=make_pair(i,10);
    for (int i=n;i;--i) {
        int len=c[i].second.length(),d=c[i].first;
        int &shu=b[d].first=0,&tmp=b[d].second=1;
        if (!len) {
            a[d]=b[d];
            continue;
        }
        for (int j=len-1;j>=0;--j) {
            int x=c[i].second[j]-'0';
            shu=Plus(shu,Multi(tmp,a[x].first));
            tmp=Multi(tmp,a[x].second);
        }
        a[d]=b[d];
    }
    int m=strlen(s+1),ans=0;
    for (int i=m,tmp=1;i;--i) {
        int x=s[i]-'0';
        ans=Plus(ans,Multi(tmp,a[x].first));
        tmp=Multi(tmp,a[x].second);
    }
    printf("%d\n",ans);
    return 0;
}

转载于:https://www.cnblogs.com/owenyu/p/7170059.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的Python代码,可以生成五力模型的雷达图。 ```python import matplotlib.pyplot as plt import numpy as np # 定义五力模型的五个方面 factors = ['竞争对手', '供应商', '客户', '替代品', '新进入者'] # 定义每个方面的得分(0-10分) competitors = [9, 4, 7, 3, 5] suppliers = [5, 8, 3, 6, 7] customers = [6, 7, 9, 2, 4] substitutes = [3, 6, 4, 9, 8] new_entrants = [8, 3, 5, 7, 6] # 定义每个方面的角度 angles = np.linspace(0, 2 * np.pi, len(factors), endpoint=False) # 将角度闭合起来 competitors = np.concatenate((competitors, [competitors[0]])) suppliers = np.concatenate((suppliers, [suppliers[0]])) customers = np.concatenate((customers, [customers[0]])) substitutes = np.concatenate((substitutes, [substitutes[0]])) new_entrants = np.concatenate((new_entrants, [new_entrants[0]])) angles = np.concatenate((angles, [angles[0]])) # 绘制雷达图 fig = plt.figure() ax = fig.add_subplot(111, polar=True) ax.plot(angles, competitors, 'o-', linewidth=2, label='竞争对手') ax.fill(angles, competitors, alpha=0.25) ax.plot(angles, suppliers, 'o-', linewidth=2, label='供应商') ax.fill(angles, suppliers, alpha=0.25) ax.plot(angles, customers, 'o-', linewidth=2, label='客户') ax.fill(angles, customers, alpha=0.25) ax.plot(angles, substitutes, 'o-', linewidth=2, label='替代品') ax.fill(angles, substitutes, alpha=0.25) ax.plot(angles, new_entrants, 'o-', linewidth=2, label='新进入者') ax.fill(angles, new_entrants, alpha=0.25) ax.set_thetagrids(angles * 180 / np.pi, factors) ax.grid(True) plt.legend(loc='best') plt.title('五力模型分析') plt.show() ``` 这段代码使用了Matplotlib库来生成雷达图。你可以将五力模型中的各个方面的得分替换成你自己的数据,然后运行代码,就可以生成相应的雷达图啦。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值