欢迎点此阅读QvQ
250
Description
给高度为 h1 的棍子 r1 个, h2 的 r2 个,轮流放,问最多放出多少种不同的高度
Solution
考虑 h1 是否等于 h2 ,再讨论即可
Code
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
struct TheBrickTowerEasyDivOne {
int find(int r1, int h1, int r2, int h2) {
if (h1 == h2) {
return 2 * min(r1, r2) + (r1 == r2 ? 0 : 1);
}
else {
return 2 * min(r1, r2) + (r1 > r2) + min(r1, r2) + (r2 > r1);
}
}
};
500
Description
将 n 个数重新排列,使得相邻两个数最大值之和尽量小,同时字典序最小。
Solution
Code
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 50;
vector<pii> s;
vector<int> ans;
bool vis[N];
struct TheBrickTowerMediumDivOne {
vector <int> find(vector <int> a) {
int n = a.size();
ans.pb(0), vis[0] = 1;
for (int i = 1; i < n; ++i) {
int p = -1;
for (int j = 0; j < n; ++j) {
if (!vis[j] && a[j] <= a[ans[i - 1]]) {
p = j;
break;
}
}
if (~p) ans.pb(p), vis[p] = 1;
else break;
}
for (int i = 0; i < n; ++i)
if (!vis[i]) s.pb(mp(a[i], i));
sort(s.begin(), s.end());
for (int i = 0; i < s.size(); ++i) ans.pb(s[i].S);
return ans;
}
};