这个div4还是比较基础的,比赛的时候写了4题就睡觉去了,早上起来花了几十分钟把剩余的题补了,总的来说还是比较适合初学者的。
A. Sum of Round Numbers
题目就不粘贴了。
就是把一个数 n n n表示成round
数,如 9876 9876 9876,输出 9000 , 800 , 70 , 6 9000,800,70,6 9000,800,70,6, 5009 5009 5009,输出 5000 , 9 5000,9 5000,9,例子一看就知道怎么搞了。
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int max(int a, int b) {
return a > b ? a : b; }
int min(int a, int b) {
return a > b ? b : a; }
const double eps = 1e-7;
#define endl '\n'
#define pb(a) push_back(a)
#define ALL(x) x.begin(), x.end()
int mypow(int x, int n) {
for (int i = 1; i <= n; ++i) x *= 10;
return x;
}
int main() {
// ios::sync_with_stdio(false);
int t;
scanf("%d", &t);
while (t--) {
string s;
cin >> s;
int n = s.size() - 1;
vector<int> ans;
for (int i = 0; i < s.size(); ++i) {
if (s[i] != '0') {
ans.pb(mypow(s[i] - '0', n));
}
n--;
}
printf("%d\n", ans.size());
for (auto it : ans) printf("%d ", it);
printf("\n");
}
return 0;
}
B. Same Parity Summands
B题有点恶心,写了很多的判断语句,首先需要知道
- 奇数+奇数=偶数
- 偶数+偶数=偶数
- 奇数+偶数=奇数
然后看题目你最终要表示成什么数的和,如果是奇数,那么就是 n = ∑ 1 k − 1 1 + ( n − k + 1 ) n = \sum_{1}^{k-1} 1+(n-k+1) n=∑1k−11+(n−k+1),如果表示成偶数,那么就是 n = ∑ 1 k − 1 2 + n − 2 × ( k − 1 ) n=\sum_{1}^{k-1}2+n-2 \times (k-1) n=∑1k−12+n−2×(k−1),如果表示不出来就是NO
。
还有一些特殊判断的,如果n=k
,那么直接输出 k k k个 1 1 1,如果k是偶数并且n是奇数,那直接NO
。
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std