Codeforces Round 904 (Div. 2) A~B

A.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
bool is_k_beautiful(int n, int k)
{
    string s = std::to_string(n);
    int digit_sum = 0;
    for (char c : s)
    {
        digit_sum += c - '0';
    }
    return digit_sum % k == 0;
}

int find_min_beautiful(int x, int k)
{
    int y = x;
    while (true)
    {
        if (is_k_beautiful(y, k))
        {
            return y;
        }
        ++y;
    }
}
void solve()
{
    ll x, k;
    cin >> x >> k;
    cout << find_min_beautiful(x, k) << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

B.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
const int N = 1e5 + 5;
ll dp[N];
void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a;
    int len = s.length();
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < len; i++)
    {
        dp[i] = 0;
        if (s[i] == '0')
        {
            a.push_back(len - i - 1);
        }
    }
    if (s[len - 1] == '1')
    {
        if (!a.empty())
        {
            dp[1] = a.back();
            a.pop_back();
        }
        else
        {
            dp[1] = -1;
        }
    }
    else
    {
        dp[1] = 0;
        a.pop_back();
    }
    for (int i = 2; i <= n; i++)
    {
        if (a.size() == 0)
        {
            dp[i] = -1;
        }
        else
        {
            dp[i] = dp[i - 1] + a.back() - i + 1;
            a.pop_back();
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << dp[i] << " \n"[i == n];
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

C.样例没搞明白,以为单纯的就是最大-最小,后面再补吧,下午还有一场

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值