关于CSP-S T37
  • 板块灌水区
  • 楼主d0j1a_1701
  • 当前回复10
  • 已保存回复10
  • 发布时间2021/9/19 21:45
  • 上次更新2023/11/4 06:10:08
查看原帖
关于CSP-S T37
248302
d0j1a_1701楼主2021/9/19 21:45

经过对拍似乎选B或选C是完全一样的,但答案上写C?

附程序:

#include <iostream>
#include <cstdlib>
#include <climits>

using namespace std;

const int M = 10000;
bool Vis[M + 1];
int F[M + 1];

void update(int &x, int y) {
	if (y < x)
		x = y;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i <= M; i++)
		F[i] = INT_MAX;
	F[4] = 1;
	int r = 0;
	while (!Vis[n]) {
		r++;
		int x = 0;
		for (int i = 1; i <= M; i++)
			if (!Vis[i] && F[i] < F[x])
				x = i;
		Vis[x] = 1;
		for (int i = 1; i <= M; i++)
			if (F[i] <= r) {//B
				int t = F[i] + F[x];
				if (i + x <= M)
					update(F[i + x], t);
				if (i != x)
					update(F[abs(i - x)], t);
				if (i % x == 0)
					update(F[i / x], t);
				if (x % i == 0)
					update(F[x / i], t);
			}
	}
	cout << F[n] << endl;
	return 0;
}
#include <iostream>
#include <cstdlib>
#include <climits>

using namespace std;

const int M = 10000;
bool Vis[M + 1];
int F[M + 1];

void update(int &x, int y) {
	if (y < x)
		x = y;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i <= M; i++)
		F[i] = INT_MAX;
	F[4] = 1;
	int r = 0;
	while (!Vis[n]) {
		r++;
		int x = 0;
		for (int i = 1; i <= M; i++)
			if (!Vis[i] && F[i] < F[x])
				x = i;
		Vis[x] = 1;
		for (int i = 1; i <= M; i++)
			if (Vis[i]) {//C
				int t = F[i] + F[x];
				if (i + x <= M)
					update(F[i + x], t);
				if (i != x)
					update(F[abs(i - x)], t);
				if (i % x == 0)
					update(F[i / x], t);
				if (x % i == 0)
					update(F[x / i], t);
			}
	}
	cout << F[n] << endl;
	return 0;
}

数据生成器:

#include <iostream>
#include <random>
#include <chrono>
using namespace std;
mt19937 mt(chrono::system_clock::to_time_t(chrono::system_clock::now()));
uniform_int_distribution<int> N(1, 10000);
int main() {
	cout << N(mt) << endl;
	//system("pause");
	return 0;
}
2021/9/19 21:45
加载中...