《打表出奇迹》
查看原帖
《打表出奇迹》
1104948
cc_lucky楼主2024/10/20 16:40

兄弟们我打表AC了

#include<bits/stdc++.h>
using namespace std;
int nums[50] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 8, 9, 6, 9, 29, 39, 38, 65, 88, 128};
int n;
int main() {
	cin >> n;
	cout << nums[n];
}

打表函数如下(k = 24时会TLE, 我这个编译器等一会就好了)

#include<bits/stdc++.h>
using namespace std;
int nums[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, ans;
int cut(int x) {
	if (x == 0) return 6;
	int cnt = 0;
	while (x) {
		cnt += nums[x % 10];
		x /= 10;
	}
	return cnt;
}
int main() {
	cout << "{";
	for (int k = 1; k <= 24; k ++) {
		ans = 0;
		n = k - 4;
		int edsum = n / 2 / 2, ed = 0;
		for (int i = 1; i <= edsum; i++) ed = ed * 10 + 1;
		for (int i = 0; i <= ed; i++) {
			if (cut(i) >= n) continue;
			for (int j = 0; j <= ed; j++) {
				if (cut(i) + cut(j) + cut(i + j) == n) {
					ans++;
				}
			}
		}
		cout << ans;
		if (k != 24) cout << ", ";
	}
	cout << "}";
}

求关注

2024/10/20 16:40
加载中...