(模拟)关于进制的瞎搞---You Are Given a Decimal String...(Educational Codeforces Round 70 (Rated for Div. 2))

题目链接:https://codeforc.es/contest/1202/problem/B

题意:

给你一串数,问你插入最少多少数可以使x-y型机器(每次+x或+y的机器,机器每次只取最低位--%10)产生这个子序列

解:

这题真的是。。。唉我真的,还是怪自己太弱吧,比如08888,8和前一个8相同的话你必须让机器输入东西(不能看着这串数反正都是一样就不输入)。

就是预处理x-y型每次加(0~9)最少需要多少次就行了,刚上蓝就rank1900+,以后多多磨练吧。

  1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
  2 #include <cstdio>//sprintf islower isupper
  3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
  4 #include <iostream>//pair
  5 #include <fstream>
  6 #include <bitset>
  7 //#include <map>
  8 //#include<unordered_map>
  9 #include <vector>
 10 #include <stack>
 11 #include <set>
 12 #include <string.h>//strstr substr
 13 #include <string>
 14 #include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
 15 #include <cmath>
 16 #include <deque>
 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
 18 #include <vector>//emplace_back
 19 //#include <math.h>
 20 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
 21 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
 22 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
 23 #define fo(a,b,c) for(register int a=b;a<=c;++a)
 24 #define fr(a,b,c) for(register int a=b;a>=c;--a)
 25 #define mem(a,b) memset(a,b,sizeof(a))
 26 #define pr printf
 27 #define sc scanf
 28 #define ls rt<<1
 29 #define rs rt<<1|1
 30 void swapp(int &a,int &b);
 31 double fabss(double a);
 32 int maxx(int a,int b);
 33 int minn(int a,int b);
 34 int Del_bit_1(int n);
 35 int lowbit(int n);
 36 int abss(int a);
 37 //const long long INF=(1LL<<60);
 38 const double E=2.718281828;
 39 const double PI=acos(-1.0);
 40 const int inf=(1<<29);
 41 const double ESP=1e-9;
 42 const int mod=(int)1e9+7;
 43 const int N=(int)2e6+10;
 44 
 45 char s[N];
 46 int l;
 47 
 48 long long mp[103][103][15],ans[20][20];
 49 
 50 void work(int a,int b)//预处理
 51 {
 52     fo(i,0,100)
 53     {
 54         fo(j,0,100)
 55         {
 56             if(i==0&&j==0)//关键:因为不能什么都不输入;
 57                 continue;
 58             mp[a][b][(a*i+b*j)%10]=mp[b][a][(a*i+b*j)%10]=min(mp[a][b][(a*i+b*j)%10],(long long)i+j);
 59         }
 60     }
 61 }
 62 
 63 void woo(int x,int y)//开始搞字符串;
 64 {
 65     fo(i,2,l)
 66     {
 67         int tt=(s[i]-'0')-(s[i-1]-'0');
 68         tt+=100;
 69         tt%=10;
 70         if(mp[x][y][tt]==inf)
 71         {
 72             ans[x][y]=-1;
 73             break;
 74         }
 75         ans[x][y]+=mp[x][y][tt];
 76     }
 77 }
 78 
 79 int main()
 80 {
 81     s[0]='0';
 82     fo(i,0,13)
 83         fo(j,0,13)
 84             fo(k,0,13)
 85                 mp[i][j][k]=inf;
 86     fo(i,0,9)
 87     {
 88         fo(j,0,9)
 89             work(i,j);
 90     }
 91     sc("%s",s+1);
 92     l=strlen(s)-1;
 93     fo(i,0,9)
 94     {
 95         fo(j,0,9)
 96         {
 97             woo(i,j);
 98         }
 99     }
100     fo(i,0,9)
101     {
102         fo(j,0,9)
103         {
104             if(ans[i][j]!=-1)
105                 ans[i][j]-=l-1;//减去已经有的就行了;
106             long long temp=ans[i][j];
107             pr("%lld ",temp);
108         }
109         pr("\n");
110     }
111     return 0;
112 }
113 
114 /**************************************************************************************/
115 
116 int maxx(int a,int b)
117 {
118     return a>b?a:b;
119 }
120 
121 void swapp(int &a,int &b)
122 {
123     a^=b^=a^=b;
124 }
125 
126 int lowbit(int n)
127 {
128     return n&(-n);
129 }
130 
131 int Del_bit_1(int n)
132 {
133     return n&(n-1);
134 }
135 
136 int abss(int a)
137 {
138     return a>0?a:-a;
139 }
140 
141 double fabss(double a)
142 {
143     return a>0?a:-a;
144 }
145 
146 int minn(int a,int b)
147 {
148     return a<b?a:b;
149 }

猜你喜欢

转载自www.cnblogs.com/--HPY-7m/p/11326527.html