(模拟)关于进制的瞎搞---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 }

原文地址:https://www.cnblogs.com/--HPY-7m/p/11326527.html

时间: 2024-08-29 04:04:39

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

Educational Codeforces Round 34 (Rated for Div. 2) B题【打怪模拟】

B. The Modcrab Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics

Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)

1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 int mn[600007],mx[600007],a[600007],pos[600007],sum[600007]; 5 int n,m; 6 int lowbit(int x){ 7 return x&(-x); 8 } 9 void add(int x,int val){//单点更新 10 while(x<60

HDU 2100 Lovekey 模拟26进制

Problem Description XYZ-26进制数是一个每位都是大写字母的数字. A.B.C.-.X.Y.Z 分别依次代表一个0 ~ 25 的数字,一个 n 位的26进制数转化成是10进制的规则如下 A0A1A2A3-An-1 的每一位代表的数字为a0a1a2a3-an-1 ,则该XYZ-26进制数的10进制值就为 m = a0 * 26^(n-1) + a1 * 26^(n-2) + - + an-3* 26^2 + an-2*26 + an-1 一天vivi忽然玩起了浪漫,要躲在学校

模拟时间进制转换,并输出当年日历

这个是朋友托我打的,不属于ACM,但觉得挺有意思,所以就放到这里了,题目有两个要求,输出当1年1月1日到前年每月的1号隔了多少天,并输出这天是星期几,然后再按格式输出这一年12个月的公历日历. 是一个挺简单的模拟,就是有点小麻烦和小细节需要注意,下面是代码: #include<iostream> #include<cstdio> #include<cstring> using namespace std; struct Node { int y,m,d,day; };

51nod 1315 合法整数集 (位操作理解、模拟、进制转换)

1315 合法整数集 题目来源: TopCoder 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 取消关注 一个整数集合S是合法的,指S的任意子集subS有Fun(SubS)!=X,其中X是一个固定整数,Fun(A)的定义如下: A为一个整数集合,设A中有n个元素,分别为a0,a1,a2,...,an-1,那么定义:Fun(A)=a0 or a1 or ... or an-1:Fun({}) = 0,即空集的函数值为0.其中,or为或操作. 现在

入门模拟——(进制转换)B1022.D进制的A+B

#include <bits/stdc++.h> #include<math.h> using namespace std; const int MAX_LEN = 100005; const int MAX_D = 31; int main(){ int a,b,n; cin>>a; cin>>b; int temp = a+b; cin>>n; int result[MAX_D]; int num = 0; do{ result[num++]

Educational Codeforces Round 20 A. Maximal Binary Matrix(模拟)

题意:给你一个n*n的全是0的矩阵,和k个数字"1",让你把这k个数字1按照从上到下,从左到右的顺序构建出来 思路:模拟即可 代码: #include <iostream> #include <cstring> using namespace std; int main() { int n,k; int data[105][105]; while(cin>>n>>k) { memset(data,0,sizeof(data)); if(k

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker(gcd模拟)

Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can

Educational Codeforces Round 35 E. Stack Sorting 模拟

Educational Codeforces Round 35 E. Stack Sorting 题意:长度为 n 的序列 a[] ,a[] 里的数是 1~n,一个空栈 s,一个空序列 b[].两个操作:把 a[] 的第一个数放到 s 里: 或者把 s 的栈顶元素加到 b[] 的末尾. 如果你能通过这两个操作把 a[] 的数最后都放入 b[] 中,且 b[] 是升序的,那就可说 a[] 是 stack-sortable . 现在给出 a[] 的前 k 个数,要你确定是否有满足 stack-sor