正文
增加 13 行删除 13 行
18 行未改动1920212223242526272829303132333435363738394041424344454647484950515253545556575818 行未改动77787980818283848586878841 行未改动18 行未改动#include <bits/stdc++.h>using namespace std;int T, n, m, digit, times;vector <int> ans;vector <int> cnt;int main(){cin >> T;while (T--){cin >> n >> m;ans.clear();cnt.clear();for (int i=1; i<10; ++i){//枚举数字long long s = 0;int c = 0;//不能从一位数开始,因为m可能是一位数while (c < n){s = s*10 + i;s %= m;if (s==0){ans.push_back(i);cnt.push_back(c+1);// 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){//等号取到,因为数字越大值越大digit = ans[i];times = n/cnt[i] * 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},{1, 0, 2}, {1, 2, 0},{2, 0, 1}, {2, 1, 0},{2, 2, 2}};```在解决过程中,我们将预处理好的序列直接进行覆盖,这样的结果一定是满足条件的对于每一种覆盖方式41 行未改动18 行未改动1920212223242526272829303132333435363738394041424344454647484950515253545556575818 行未改动77787980818283848586878841 行未改动18 行未改动#include <bits/stdc++.h>using namespace std;int T, n, m, digit, times;vector <int> ans;vector <int> cnt;int main(){cin >> T;while (T--){cin >> n >> m;ans.clear();cnt.clear();for (int i=1; i<10; ++i){//枚举数字long long s = 0;int c = 0;//不能从一位数开始,因为m可能是一位数while (c < n){s = s*10 + i;s %= m;if (s==0){ans.push_back(i);cnt.push_back(c+1);// 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){//等号取到,因为数字越大值越大digit = ans[i];times = n/cnt[i] * 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},{1, 0, 2}, {1, 2, 0},{2, 0, 1}, {2, 1, 0},{2, 2, 2}};```在解决过程中,我们将预处理好的序列直接进行覆盖,这样的结果一定是满足条件的对于每一种覆盖方式41 行未改动