A. lyynuu
思路:
先了解子序列的概念:
在数学中,某个序列的子序列是从最初序列通过去除某些元素但不破坏余下元素的相对位置(在前或在后)而形成的新序列
接下来我们就思考什么样的字符串可以让子序列 lynu
形成的数量最多,显然当相同字符连在一起时可以形成尽可能多的 lynu
,例如: llyynnuu
可以形成 \(16\) 个
l l y y n n u u 字符
1 2 3 4 5 6 7 8 位置
可以选:
1 2 5 7
1 2 5 8
1 2 6 7
···
2 4 6 8
总计 2 x 2 x 2 x 2 = 16 种
如果 \(n\) 不能整除 lynu
的个数时,余下的全都变成 u
放最后就好了,最后只需要把这部分也加上就行了,过程看代码。
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
ll n, l = 4;
cin >> n;
ll a = n / l, b = n % l;
if (n < l) cout << 0 << endl;
else if (n == l) cout << 1 << endl;
else {
ll d = pow(a + 1, b) * pow(a, l - b);
cout << d;
}
return 0;
}
B. 输出ASCII码
思路:无
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int main() {
//cin.tie(0)->ios::sync_with_stdio(0);
char a;
cin >> a;
printf("%d", a);
return 0;
}
C. 小雨雨打起电动超勇的
思路:无
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
int t1, t2, t3, t4;
cin >> t1 >> t2 >> t3 >> t4;
int q;
bool f = false;
cin >> q;
while (q--) {
int y;
cin >> y;
if ((t1 <= y && y <= t2) || (t3 <= y && y <= t4))
f = true;
}
if (f) cout << "Y";
else cout << "N";
return 0;
}
D. 熊熊,觅食!
思路:
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
int n;
cin >> n;
n = abs(n);
int a = n / 3, b = n % 3;
if (b) cout << a + 1;
else cout << a;
return 0;
}
E. 小雨雨查找数字
思路:
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
int n;
cin >> n;
vector<int>a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
int s;
cin >> s;
cout << count(a.begin(), a.end(), s);
return 0;
}
F. 连续奇数的和
思路:无
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
int x, y, sum = 0;
cin >> x >> y;
for (int i = min(x, y) + 1; i < max(x, y); i++)
if (i & 1) sum += i;
cout << sum;
return 0;
}
G. 斐波那契数列
思路:
递推
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int a[N];
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
int n;
cin >> n;
a[1] = 1;
a[2] = 1;
for (int i = 3; i <= n; i++)
a[i] = a[i - 1] + a[i - 2];
cout << a[n];
return 0;
}
H. 玩游戏
思路:
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int a[N];
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
char a, b;
cin >> a >> b;
if (a == 'S' && b == 'J' || a == 'J' && b == 'B' || a == 'B' && b == 'S') printf("Alice");
else if (a == b)printf("try again~");
else printf("Bob");
return 0;
}
I. 排个序
思路:
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int a[N];
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++)
cout << a[i] << " \n"[i == n - 1];
return 0;
}
J. 签个到
思路:
代码:
C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
int a[N];
int main() {
cin.tie(0)->ios::sync_with_stdio(0);
cout << "不去上课就不会迟到啦~" << endl;
return 0;
}