• You Are Given a Decimal String..(最短路,思维)


    Suppose you have a special xx-yy-counter. This counter can store some value as a decimal number; at first, the counter has value 00.

    The counter performs the following algorithm: it prints its lowest digit and, after that, adds either xx or yy to its value. So all sequences this counter generates are starting from 00. For example, a 44-22-counter can act as follows:

    1. it prints 00, and adds 44 to its value, so the current value is 44, and the output is 00;
    2. it prints 44, and adds 44 to its value, so the current value is 88, and the output is 0404;
    3. it prints 88, and adds 44 to its value, so the current value is 1212, and the output is 048048;
    4. it prints 22, and adds 22 to its value, so the current value is 1414, and the output is 04820482;
    5. it prints 44, and adds 44 to its value, so the current value is 1818, and the output is 0482404824.

    This is only one of the possible outputs; for example, the same counter could generate 02468024680240246802468024 as the output, if we chose to add 22 during each step.

    You wrote down a printed sequence from one of such xx-yy-counters. But the sequence was corrupted and several elements from the sequence could be erased.

    Now you'd like to recover data you've lost, but you don't even know the type of the counter you used. You have a decimal string ss — the remaining data of the sequence.

    For all 0≤x,y<100≤x,y<10, calculate the minimum number of digits you have to insert in the string ss to make it a possible output of the xx-yy-counter. Note that you can't change the order of digits in string ss or erase any of them; only insertions are allowed.

    Input

    The first line contains a single string ss (1≤|s|≤2⋅1061≤|s|≤2⋅106, si∈{0−9}si∈{0−9}) — the remaining data you have. It's guaranteed that s1=0s1=0.

    Output

    Print a 10×1010×10 matrix, where the jj-th integer (00-indexed) on the ii-th line (00-indexed too) is equal to the minimum number of digits you have to insert in the string ss to make it a possible output of the ii-jj-counter, or −1−1 if there is no way to do so.

    Example

    input

    Copy

    0840
    

    output

    Copy

    -1 17 7 7 7 -1 2 17 2 7 
    17 17 7 5 5 5 2 7 2 7 
    7 7 7 4 3 7 1 7 2 5 
    7 5 4 7 3 3 2 5 2 3 
    7 5 3 3 7 7 1 7 2 7 
    -1 5 7 3 7 -1 2 9 2 7 
    2 2 1 2 1 2 2 2 0 1 
    17 7 7 5 7 9 2 17 2 3 
    2 2 2 2 2 2 0 2 2 2 
    7 7 5 3 7 7 1 3 2 7 
    

    Note

    Let's take, for example, 44-33-counter. One of the possible outcomes the counter could print is 0(4)8(1)4(7)00(4)8(1)4(7)0 (lost elements are in the brackets).

    One of the possible outcomes a 22-33-counter could print is 0(35)8(1)4(7)00(35)8(1)4(7)0.

    The 66-88-counter could print exactly the string 08400840.

    思路:

    1,问题在于如何才能想起这个floy,

    要求只能插数,距离是i或者j,问题最小插入的数的个数=》距离相当于floy初始化里的内容,最小个数相当于最短路,(a直接到b,还是经过k过渡),结合数据范围即可

    参看floy

    代码:

    1. #include
    2. using namespace std;
    3. #define int long long
    4. #define vec vector
    5. const int maxj=2e6+1000,mod=998244353,inf=0x7f7f7f7f7f7f7f;
    6. int a[20][20];
    7. string s;
    8. int b[120][120];
    9. int ask(int x,int y){//注重学最短路floy
    10. memset(b,mod,sizeof(b));
    11. for(int i=0;i<10;++i){
    12. b[i][(i+x)%10]=b[i][(i+y)%10]=1;
    13. }//初始化
    14. for(int k=0;k<10;++k){
    15. for(int i=0;i<10;++i){
    16. for(int j=0;j<10;++j){
    17. b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
    18. }
    19. }//floy的板子,
    20. }int ans=0;
    21. for(int i=0;isize()-1;++i){
    22. int aa=s[i]-'0',bb=s[i+1]-'0';
    23. if(b[aa][bb]>=mod)return -1;
    24. ans+=b[aa][bb]-1;//a到b一步到位时,不需插入
    25. }return ans;
    26. }
    27. void solve(){
    28. //暴力
    29. cin>>s;
    30. for(int i=0;i<10;++i){
    31. for(int j=0;j<10;++j){
    32. cout<<ask(i,j)<<' ';//暴力即可
    33. }cout<<'\n';
    34. }
    35. }
    36. signed main(){
    37. ios::sync_with_stdio(0);//能不用c语言的输入输出,尽量不要用
    38. cin.tie(0);
    39. cout.tie(0);
    40. int t;
    41. // cin>>t;
    42. t=1;
    43. while(t--)solve();
    44. return 0;
    45. }

  • 相关阅读:
    JSNet: Joint Instance and Semantic Segmentation of 3D Point Clouds
    人工智能核心基础 - 规划和概要
    CISP-PTE真题演示
    通过maven基于springboot项目构建脚手架archetype
    hadoop小知识
    复杂SQL收集
    TiDB Lightning 并行导入
    使用 Flutter 与 Firebase 制作 I/O 弹球游戏
    leetcode 234. 回文链表
    中国预制菜行业发展形势与前景规划建议报告2022-2028年版
  • 原文地址:https://blog.csdn.net/m0_63054077/article/details/125997209