mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:28:47 +00:00
P4377 [USACO18OPEN] Talent Show G
https://www.luogu.com.cn/record/85978845
This commit is contained in:
parent
d2aea3e36a
commit
aaba30fc60
56
Luogu/P4377/P4377.cpp
Normal file
56
Luogu/P4377/P4377.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 255,
|
||||
W = 1005;
|
||||
const double eps = 1e-6;
|
||||
|
||||
int n, w, a[N], b[N];
|
||||
double f[W];
|
||||
|
||||
bool check(double x) {
|
||||
std::fill_n(f + 1, w, -1e9);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = w; j >= 0; j--) {
|
||||
int k = std::min(w, j + a[i]);
|
||||
|
||||
f[k] = std::max(f[k], f[j] + b[i] - x * a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return f[w] >= 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> w;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i] >> b[i];
|
||||
}
|
||||
|
||||
double l = 0,
|
||||
r = 1e6;
|
||||
|
||||
while (r - l > eps) {
|
||||
double mid = (l + r) / 2;
|
||||
|
||||
if (check(mid)) {
|
||||
l = mid;
|
||||
} else {
|
||||
r = mid;
|
||||
}
|
||||
}
|
||||
|
||||
cout << static_cast<int>(std::floor(l * 1000)) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
Luogu/P4377/data/P4377_1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_10.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_10.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_2.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_2.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_3.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_3.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_4.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_4.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_5.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_5.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_6.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_6.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_7.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_7.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_8.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_8.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_9.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4377/data/P4377_9.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4377/data/P4377_9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user