版本比较
5.?比赛题解
正文
增加 13 行删除 13 行
18 行未改动192021222323242525262728293031313233333435363738383940404142434344454647484949505152525354545556575818 行未改动77787980818281828384848586878841 行未改动18 行未改动#include <bits/stdc++.h>using namespace std;int T, n, m, digit, times;vector <int> ans;vector <int> cnt; vector <int> cnt;int main(){
cin >> T; while (T--){ cin >> n >> m; ans.clear(); cnt.clear(); for (int i=1; i<10; ++i){//枚举数字 for (int i=1; i<10; ++i){//枚举数字 long long s = 0; int c = 0;//不能从一位数开始,因为m可能是一位数 int c = 0;//不能从一位数开始,因为m可能是一位数 while (c < n){ s = s*10 + i; s %= m; if (s==0){ ans.push_back(i); ans.push_back(i); cnt.push_back(c+1);// break这里不能这么做 // break这里不能这么做 } c++; } } } if (ans.size() == 0) cout << -1 << endl; else{ int lft = 100000;//剩下的位数越少,数越大 for (int i=0; i<ans.size(); ++i){ if (n % cnt[i] <= lft){//等号取到,因为数字越大值越大 if (n % cnt[i] <= lft){//等号取到,因为数字越大值越大 digit = ans[i]; times = n/cnt[i] * cnt[i]; lft = n%cnt[i];//忘了更新了!!! lft = n%cnt[i];//忘了更新了!!! } } } cout << string(times, (char)(48+digit)) << endl; } } return 0;18 行未改动{2,2,2}重复。```我们定义 `t` 数组表示任意相邻的三个数可能产生的9种情况```int t[9][3] = {{0, 0, 0}, {1, 1, 1}, {0, 1, 2}, {0, 2, 1}, int t[9][3] = {{0, 0, 0}, {1, 1, 1},{0, 1, 2}, {0, 2, 1},{1, 0, 2}, {1, 2, 0},{2, 0, 1}, {2, 1, 0}, {2, 0, 1}, {2, 1, 0},{2, 2, 2}};```在解决过程中,我们将预处理好的序列直接进行覆盖,这样的结果一定是满足条件的对于每一种覆盖方式41 行未改动