1. 最大优美排列
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << n - i << " ";
}
}
// 64 位输出请用 printf("%lld")
2. 小红走字符串
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
long k;
cin >> n >> k;
string str;
cin >> str;
for (int i = 1; i < str.size(); i++) {
int consume = str[i] - str[i - 1];
k -= consume;
if (k < 0 && i != str.size() - 1) {
cout << -1;
}
}
cout << k;
}
// 64 位输出请用 printf("%lld")
3.
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> veca(n);
unordered_map<int, int> mpa;
for (int i = 0; i < n; i++) {
cin >> veca[i];
mpa[veca[i]] = i;
}
vector<int> vecb(n);
unordered_map<int, int> mpb;
for (int i = 0; i < n; i++) {
cin >> vecb[i];
mpb[vecb[i]] = i;
}
// 右值对象如果没有加L强转,相当于还是int,一样会越界 = =
long maxNum = n * (n + 1L);
long maxNum = n * (n + 1);
for (int i = 0; i < n; i++) {
int posa = mpa[veca[i]];
int posb = mpb[veca[i]];
int numSame = 0;
while (posa < n && posb < n && veca[posa] == vecb[posb]) {
numSame++;
posa++;
posb++;
}
maxNum -= numSame;
}
cout << maxNum;
}