蒟蒻只做出了两道签到题…剩下的题待补。
A.Potion Making
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int k; cin >> k;
int d = gcd(k, 100);
cout << 100 / d << '\n';
}
}
B.Permutation Sort
一开始没啥思路,就拿着本草稿纸自己造数据玩,慢慢地发现一共也就分几种情况
- 完全符合题意的
- 只有一对位置不一样的,这里又分两种情况
(1)首尾分别是最大数和最小数
(2)不满足(1)的 - 开头是最小数或者末尾是最大数
- 首尾分别是最大数和最小数
- 不满足上述四条的
第一种情况显然是0
第二种情况:(1)这里要把最小的运到前面,把最大的运到后面,然后中间再整理一次,所以一共三次(2)因为只有一对不一样,所以整理一次就够了
第三种情况:直接重排(n-1)长度的子串,一次就够了
第四种情况:与第二种情况的(1)一样的
第五种情况:重排两次(n-1)长度的子串就够了,想不出来的自己整一些例子看看就懂了
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
using namespace std;
int a[55];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ck = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] != i)ck++;
}
if (ck == 0) {
cout << 0 << '\n'; continue;
}
if (ck == 2) {
if (a[1] == n && a[n] == 1)cout << 3 << '\n';
else cout << 1 << '\n';
continue;
}
if (a[1] == 1 || a[n] == n) {
cout << 1 << '\n'; continue;
}
if (a[1] == n && a[n] == 1) {
cout << 3 << '\n'; continue;
}
cout << 2 << '\n';
}
}
C.还没看题
D.Armchairs
一直在想怎么贪心,结果正解是DP
有空再补