HRBUST 2462——DQS And Guido Mista【贪心 & 模拟】

题目传送门


Description

DQS watches JoJo’s Bizarre Adventure: Golden Wind a lot, and her favorite character is Guido Mista.

One day, Mista had a dream. In his dream, he has a revolver (a kind of pistol) with n rounds of bullets. He wants to shoot all his bullets at Diablo, the ultimate boss with the stand King Crimson.

Initially, bullets are without gunpowder, so he needs to fill gunpowder into the bullets. For every bullet, the gunpowder filled in is at least 1 and at most 9. Also, the sum of used gunpowder must be a perfect square number, so that Mista will feel happy. (For specific definition, see the hint.)

To make the plan smooth and himself happy, he needs to shoot the bullets in the smallest lexicographical order. Please output the required shooting plan.


Input

Multiple test cases. Read to the end of the file.

For every line, there’s an integer .


Output

For every test case, output the plan in a line. There’s no space between two digits. See sample output for detail.


Sample Input

1

2

3


Sample Output

1

13

112


Hint

A perfect square number x is a certain integer y’s square. That’s to say, x=y^2.


Source

"科林明伦杯"哈尔滨理工大学第九届程序设计团队赛


题意

给一个数 n ,代表n次操作。每次操作为1~9,求n次操作后,使得得到的数的各个位相加,是一个平方数,求出这个最小的满足条件的数。


题解

  • 每次最小1,所以默认n位1
  • 从后往前贪心求解即可

AC-Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main() {
	int n;
	while (cin >> n) {
		string str(n, '1');
		int sum = ceil(sqrt(n)) * ceil(sqrt(n));
		int dt = sum - n;
		int p = n - 1;
		while (dt > 0) {
			str[p] = dt >= 8 ? 8 + '1' : dt + '1';
			dt -= dt >= 8 ? 8 : dt;
			p--;
		}
		cout << str << endl;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值