ABC363D求调(玄2关)
  • 板块学术版
  • 楼主LukeLuke
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/7/20 22:21
  • 上次更新2024/7/20 22:25:31
查看原帖
ABC363D求调(玄2关)
706627
LukeLuke楼主2024/7/20 22:21
#include <bits/stdc++.h>
using namespace std;

#define int long long

int ans[100];

signed main() {
	int n;
	scanf("%lld", &n);
	int sum = 1;
	for (int i = 1; ; i++) {
		if (sum + pow(10, (i + 1) / 2 - 1) * 9 >= n) {
			for (int j = 1; j <= (i + 1) / 2; j++) {
				for (int k = (j == 1 ? 1 : 0); k < 10; k++) {
					int kk = (k + (j != 1)) * pow(10, (i + 1) / 2 - j);
					if (sum + kk > n) {
						sum += (k - (j == 1)) * pow(10, (i + 1) / 2 - j);
						ans[j] = k, ans[i - j + 1] = k;
						break;
					} else if (sum + kk == n) {
						sum += kk;	
						ans[j] = k, ans[i - j + 1] = k;
						break;
					}	
				}
			}
			for (int j = 1; j <= i; j++) printf("%lld", ans[j]);
				puts("");
			return 0;
		} else {
			sum += pow(10, (i + 1) / 2 - 1) * 9;
		}
	}
	return 0;
}
2024/7/20 22:21
加载中...