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
是已经按照排序好的,不用改变
② 输出 1
其中有一段是乱的,且里面没有 a[ i ] = i
③ 输出 2
其中有一段是乱的,且里面有 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;
}