Codeforces Round #640 (Div. 4)解题报告

这个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=1k11+(nk+1,如果表示成偶数,那么就是 n = ∑ 1 k − 1 2 + n − 2 × ( k − 1 ) n=\sum_{1}^{k-1}2+n-2 \times (k-1) n=1k12+n2×(k1),如果表示不出来就是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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值