社区讨论
关于同步流的奇妙错误
P1833樱花参与者 3已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 6 条
- 当前快照
- 1 份
- 快照标识符
- @lo7hzbzh
- 此快照首次捕获于
- 2023/10/27 02:08 2 年前
- 此快照最后确认于
- 2023/10/27 02:08 2 年前
算法:二进制分解+01背包
关了同步流 WA 0pts:
CPP#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct tree {int t, c, p;} in[maxn], a[maxn * 1000];
int n, Time, h1, m1, h2, m2, tot, f[maxn];
char c;
int main() {
ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
scanf("%d%c%d%d%c%d%d", &h1, &c, &m1, &h2, &c, &m2, &n);
Time = (h2 - h1) * 60 + m2 - m1;
for (int i = 1; i <= n; i++) {
cin >> in[i].t >> in[i].c >> in[i].p;
if (in[i].p == 0) in[i].p = 1e3+5;
}
for (int i = 1; i <= n; i++) {
int sum = in[i].p, cur = 1;
while (sum > 0) {
int tmp;
if (sum >= cur) tmp = cur, sum = sum - cur;
else tmp = sum, sum = 0;
a[++tot] = {in[i].t * tmp, in[i].c * tmp, 0};
cur = (cur << 1);
}
}
for (int i = 1; i <= tot; i++) {
for (int j = Time; j >= a[i].t; j--) {
f[j] = max(f[j], f[j - a[i].t] + a[i].c);
}
}
cout << f[Time] << endl;
return 0;
}
开了 AC 100pts:
CPPusing namespace std;
const int maxn = 1e5 + 5;
struct tree {
int t, c, p;
} in[maxn], a[maxn * 1000];
int n, Time, h1, m1, h2, m2, tot, f[maxn];
char c;
int main() {
scanf("%d%c%d%d%c%d%d", &h1, &c, &m1, &h2, &c, &m2, &n);
Time = (h2 - h1) * 60 + m2 - m1;
for (int i = 1; i <= n; i++) {
cin >> in[i].t >> in[i].c >> in[i].p;
if (in[i].p == 0) in[i].p = 1e3+5;
}
for (int i = 1; i <= n; i++) {
int sum = in[i].p, cur = 1;
while (sum > 0) {
int tmp;
if (sum >= cur) tmp = cur, sum = sum - cur;
else tmp = sum, sum = 0;
a[++tot] = {in[i].t * tmp, in[i].c * tmp, 0};
cur = (cur << 1);
}
}
for (int i = 1; i <= tot; i++) {
for (int j = Time; j >= a[i].t; j--) {
f[j] = max(f[j], f[j - a[i].t] + a[i].c);
}
}
cout << f[Time] << endl;
return 0;
}
why?? 卡了好久,由于本人习惯用cin随手把同步流关了,然后下了一个数据发现本地能过就把那行删了然后就过了。。
吸氧无效,求解答qwq
回复
共 6 条回复,欢迎继续交流。
正在加载回复...