求助!
查看原帖
求助!
112109
Alphaban楼主2020/10/19 22:10

求hack数据或者查错

#include<stdio.h>
#include<string.h>
#include<iostream>
const int M = 6000, inf = 0x3f3f3f3f;
using namespace std;
int n,  a, b, f[2 * M + 5], g[2 * M + 5];

int min(int x, int y) {return x < y ? x : y;}

int main() {
	freopen("tx.in", "r", stdin);
	freopen("tx.out", "w", stdout);
	scanf("%d", &n);memset(f, 0x3f, sizeof(f));
	for(int i = 1; i <= n; ++i) {
		scanf("%d%d", &a, &b);
		if (i == 1) {
			f[a - b + M] = 0;
			f[b - a + M] = min(f[b - a + M], f[a - b + M]);
			continue;
		}
		for(int j = M; j >= -M; --j) {
			g[j + M] = f[j + M];
			f[j + M] =  inf;
		}
		for(int j = M; j >= -M; --j)
			if (j + a - b >= -M)
				f[j + a - b + M] = g[j + M];
		for(int j = M; j >= -M; --j)
			if (j + b - a >= -M)
				f[j + b - a + M] = min(g[j + M] + 1, f[j + b - a + M]);		 
	}
	printf("%d", f[M]);
	return 0;
}
2020/10/19 22:10
加载中...