RE70分蒟蒻求助
查看原帖
RE70分蒟蒻求助
234224
青鸟_Blue_Bird楼主2020/6/12 20:33

RT,为什么会是70分??? 好几个点RE了。

记录

#include <bits/stdc++.h>
using namespace std;
#define N 1000010
#define M 3010
#define isdigit(c) ((c)>='0'&&(c)<='9')

int read(){
	int x = 0, s = 1;
	char c = getchar();
	while(!isdigit(c)){
		if(c == '-')s = -1;
		c = getchar();
	}
	while(isdigit(c)){
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * s;
}

int n, m, p;
int x[N], y[N];
int f[M][M];
int low[N], high[N];
bool vis[N];

int main(){
//	freopen("P1941_7.in", "r", stdin);
	cin >> n >> m >> p;
	for(int i = 1;i <= n; i++){
		cin >> x[i] >> y[i];
	} 
	for(int i = 1;i <= n; i++)
		low[i] = 1, high[i] = m;
	int a, b, c;
	for(int i = 1;i <= p; i++){
//		scanf("%d%d%d", &a, &b ,&c);
		cin >> a >> b >> c;
		vis[a] = 1;
		low[a] = b + 1;
		high[a] = c - 1;
	}
	memset(f, 0x3f, sizeof(f));
	for(int i = 1;i <= m; i++) f[0][i] = 0;
	for(int i = 1;i <= n; i++){
		for(int j = x[i] + 1; j <= m + x[i]; j++)
			f[i][j] = min(f[i - 1][j - x[i]] + 1, f[i][j - x[i]] + 1);
		for(int j = m + 1; j <= m + x[i]; j++)
			f[i][m] = min(f[i][j], f[i][m]);
		for(int j = 1;j <= m - y[i]; j++)
			f[i][j] = min(f[i][j], f[i - 1][j + y[i]]);
		for(int j = 1;j < low[i]; j++)
			f[i][j] = f[0][0];
		for(int j = high[i] + 1; j <= m; j++)
			f[i][j] = f[0][0];
	}
	int ans = f[0][0];
	for(int i = 1;i <= m; i++)
		ans = min(ans, f[n][i]);
	if(ans < f[0][0]) printf("1\n%d\n", ans);
	else {
		int i, j;
		for(i = n; i > 0; i--){
			for(j = 1;j <= m; j++)
				if(f[i][j] < f[0][0]) break;
			if(j <= m) break;
		}
		ans = 0;
		for(int h = 1;h <= i; h++)
			if(vis[h]) ans++;
		printf("0\n%d\n", ans);
	}
	return 0;
}

最开始以为是快读的问题,换成scanf和cin依然没用

2020/6/12 20:33
加载中...