1模拟即可#include <bits/stdc++.h>using namespace std;int main(){    int n;    cin >> n;    vector<int> arr(n);    for (int i = 0; i < n; i++)        cin >> arr[i];    int res = 0;    for (auto num : arr)    {        int cur = 0;        string s = to_string(num);        for (int i = 0; i < s.size(); i++)        {            if (s[i] != '0')            {                cur++;            }        }        res += cur;    }    cout << res;}// 64 位输出请用 printf("%lld")2直接左上角一行一行走#include <bits/stdc++.h>using namespace std;int main(){    // 不需要回到原点,直接从1 1位置一行一行的走就可以了    int n, m;    cin >> n >> m;    string res = "", dd = "", aa = "";    for (int j = 0; j < m - 1; j++)        dd += "D";    for (int j = 0; j < m - 1; j++)        aa += "A";    for (int i = 0; i < n; i++)    {        if (i % 2)        {            res += aa;        }        else        {            res += dd;        }        if (i != n - 1)            res += "S";    }    cout << "1 1" << endl;    cout << res << endl;    return 0;}// 64 位输出请用 printf("%lld")3找规律,删除的方法是 每一轮隔一个删一个(保证次数最小),因此考虑2的幂次,保留的字符是a,需要删的字符是bk 要删的字符串1 a2 aa3 aaaa (aaaa=>aa=>a=>"")4 aaaaaaaa (aaaaaaaa=>aaaa=>aa=>a=>"")即要删的字符串是 2^(k-1)个,然后补上a即可#include <bits/stdc++.h>using namespace std;// 不相邻怎么理解// 一轮一轮删,每轮删一半// 需要删的字符串长度是 2^(k-1)个字符串int main(){    int n, k;    cin >> n >> k;    int cnt = pow(2, k - 1);    // 测试边缘case :直接-1 是10%数据,也得满足    if (n <= cnt * 2)    {        cout << -1;        return 0;    }    int rest = n - cnt;    for (int i = 0; i < rest; i++)        cout << 'a';    for (int i = 0; i < cnt; i++)        cout << 'b';    return 0;}
点赞 7
评论 4
全部评论

相关推荐

不愿透露姓名的神秘牛友
09-23 18:40
点赞 评论 收藏
分享
笑着秋招😊:我一直认为努力有回报是一件很幸福很幸福的事情,恭喜你
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务