Codeforces Global Round 7
【A.Bad Ugly Numbers】
【题目大意】
让你找一个由n个数字组成且不能被任意位上的数字整除并且不包含0的数字
【解题思路】
考虑n个数字只有2和3,那么只要构造一个不能被2和3整除的数就好了
【AC代码】
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int maxn = 1e6 + 10;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
if (n == 1) {
cout << -1 << endl;
}
else {
int nn = (n - 1) % 3 == 0 ? n - 2 : n - 1;
for (int i = 1; i <= nn; ++i) cout << 2;
for (int i = nn + 1; i <= n; ++i) cout << 3;
cout << endl;
}
}
return 0;
}
【B.Maximums】
【题目大意】
x[i] = max(0, a[1], … , a[i - 1])
b[i] = a[i] - x[i]
给你b数组让你重新构造满足条件的a数组
【解题思路】
b[i] = a[i] - x[i] = a[i] - max(0, a[1], … , a[i - 1])
a[i] = b[i] + max(0, a[1], … , a[i - 1])
那么a[1] = b[1]是显然的
a[2] = b[2] + max(0, a[1])
a[3] = b[3] + max(0, a[1], a[2])
…
令Max = max(0, a[1], … , a[i - 1])
a[i] = b[i] + Max
容易发现满足递推关系
【AC代码】
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int maxn = 1e6 + 10;
ll a[maxn], b[maxn];
int main() {
ios::sync_with_stdio(0);
cin