2020 年百度之星·程序设计大赛 - 初赛一
读题读错能卡死
A
读错, 直接完全背包, 还怀疑自己菜刀敲个完全背包都能wa半天
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; _; --_) {
cin >> n >> m;
int ans = 1e9;
rep (i, 1, n) {
int a, b; cin >> a >> b;
ans = min(ans, ((m - 1) / a + 1) * b);
}
cout << ans << '\n';
}
return 0;
}
B
搜索
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int g[] = {60, 62, 65, 67, 70, 75, 80, 85, 90, 95, 101};
double h[] = {1, 1.7, 2.0, 2.3, 2.7, 3.0, 3.3, 3.7, 4.0, 4.3};
double ans = 0;
void dfs(int k, int w, double cur) {
if (k == 5) { ans = max(ans, cur); return; }
rep (i, 0, w) {
if (g[i] > n) break;
n -= g[i];
dfs(k + 1, i, cur + h[i]);
n += g[i];
}
dfs(k + 1, 0, cur);
}
int main() {
IO;
for (cin >> _; _; --_) {
cin >> n;
dfs(1, 9, 0);
printf("%.1lf\n", ans);
}
return 0;
}
C
搜索,动态规划
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int _, n, m;
int z[1001][1001];
int f[1001][1001];
int dfs(int a, int b) {
if (a == 0 || b == 0) return 0;
if (f[a][b] != -1) return f[a][b];
if (z[a][b] == - 1) z[b][a] = z[a][b] = __gcd(a, b);
f[a][b] = max(dfs(a - 1, b), dfs(a, b - 1)) + (z[a][b] == 1);
return f[b][a] = f[a][b];
}
int main() {
IO;
memset(z, -1, sizeof z);
memset(f, -1, sizeof f);
for (cin >> _; _; --_) {
int a, b; cin >> a >> b;
cout << dfs(a, b) << '\n';
}
return 0;
}
D
读错题,直接卡死, 以为多个城市, 且食物相互独立, 敲了半天, debug了半天
我的天, 出去工作也算城市人口, 语文down down,
啥方法都写变了, nm硬是样例都过不去, 语文理解题艹
样例也没个解释, 头疼
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 2e5 + 5;
int n, m, _, k;
int v[7][7], x, y, ans;
int a[501][501];
VI va;
bool check(int a, int b) {
a += x, b += y;
return (a < 1 || a > n || b < 1 || b > n);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; _; --_) {
cin >> n >> k >> m;
rep (i, 1, n)
rep (j, 1, n) cin >> a[i][j];
ans = 1e9;
rep (i, 1, n)
rep (j, 1, n) {
int dis = (abs(m - i) + abs(k - j) + 1) >> 1;
x = i, y = j;
VI().swap(va);
rep (ii, -3, 3)
rep (jj, -3 + abs(ii), 3 - abs(ii))
if (check(ii, jj) == 0 && (ii || jj)) va.pb(a[ii + x][jj + y]);
sort(all(va));
int cur = 0, num = 0, g = a[x][y], t = dis;
rep (k, 1, 8) {
while (cur < 8 * sqr(k)) ++t, cur += g;
if (va.empty()) continue;
g += va.back(); va.pop_back();
}
ans = min(ans, t);
}
cout << ans << '\n';
}
return 0;
}