关于同步流的奇妙错误
  • 板块P1833 樱花
  • 楼主Epi4any
  • 当前回复6
  • 已保存回复6
  • 发布时间2022/11/20 22:33
  • 上次更新2023/10/27 02:08:07
查看原帖
关于同步流的奇妙错误
374769
Epi4any楼主2022/11/20 22:33

算法:二进制分解+01背包

关了同步流 WA 0pts:

#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:

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() {
	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

2022/11/20 22:33
加载中...