牛客——第二届“重科杯”重庆科技大学程序设计竞赛(题解)

B - Haoo的异或

思路:1^2^3^……^n 的结果是 1 , n+1 , 0 , n (四个一循环)

#include <bits/stdc++.h>

using namespace std;

void solve()
{
    int n;
    cin >> n;
    if (n % 4 == 1)
        cout << "1\n";
    else if (n % 4 == 3)
        cout << "0\n";
    else
        cout << "no one\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

D - 构造字符串

#include <bits/stdc++.h>

using namespace std;
string s1 = "cqustsuq", s2 = "tsuqcqus";
// cqust   tsuqc
void solve()
{
    int x, y;
    cin >> x >> y;
    string s;
    int ans = min(x, y);
    if (x == 1 && y == 0)
    {
        cout << "cqust\n";
        return;
    }
    if (x == 0 && y == 1)
    {
        cout << "tsuqc\n";
        return;
    }
    if (x > y)
    {
        for (int i = 0; i < ans; i++)
            s += s1;
        for (int i = 0; i < x - ans; i++)
            s += "cqust";
    }
    else if (x == y)
    {
        for (int i = 0; i < ans; i++)
            s += s1;
    }
    else if (x < y)
    {
        for (int i = 0; i < ans; i++)
            s += s2;
        for (int i = 0; i < y - ans; i++)
            s += "tsuqc";
    }
    cout << s << '\n';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

/*
2 1
cqustsuqcqust

2 2
cqustsuq|cqustsuq
*/

E - 奇怪的排序

思路:输出结果为 0 / 1 / 2 

① 输出 0 \rightarrow 是已经按照排序好的,不用改变

② 输出 1 \rightarrow 其中有一段是乱的,且里面没有 a[ i ] = i

③ 输出 2 \rightarrow 其中有一段是乱的,且里面有 a[ i ] =i

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 10;
int a[N], b[N];

void solve()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    if (is_sorted(a + 1, a + n + 1))
    {
        cout << "0\n";
        return;
    }
    int i = 1, j = n;
    while (a[i] == i)
        i++;
    while (a[j] == j)
        j--;
    for (int k = i; k <= j; k++)
    {
        if (a[k] == k)
        {
            cout << "2\n";
            return;
        }
    }
    cout << "1\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

J - 切割 01 串

思路:只要有 1 就可以拆出 n - 1 次,否则就是 0 次

#include <bits/stdc++.h>

using namespace std;

void solve()
{
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1')
            ans = s.size() - 1;
    }
    cout << ans << '\n';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

July.19th

感谢各位对我的支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值