[2018-4-8]BNUZ套题比赛div2 CodeForces 934B A Prosperous Lot【补】

B. A Prosperous Lot
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.

Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.

He would like to find a positive integer n not greater than 1018, such that there are exactly k loops in the decimal representation of n, or determine that such n does not exist.

loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.

Input

The first and only line contains an integer k (1 ≤ k ≤ 106) — the desired number of loops.

Output

Output an integer — if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positivedecimal integer not exceeding 1018.

Examples
input
Copy
2
output
Copy
462
input
Copy
6
output
Copy
8080

题意:输入一个数k, 随意输出 一个数 包含k个环 ,开头要非0;9、0、6、4 一个环; 8 两个环;

题解:special judge的题,随意输出什么数都可以, 第一位不能是0, 题目限制输出小于10的18次方的数, 假设全部是8时也就是 k <= 36 时 正常输出, k > 36 时输出 -1

AC代码:

#include <bits/stdc++.h>

using namespace std;

int main() {
	string a;
	int n;
	cin >> n;
	if (n > 36)
		return !printf("%d\n", -1);
	while (n) {
		if (n >= 2) {
			a += "8";
			n -= 2;
		} else {
			a += "9";
			n--;
		}
	}
	cout << a << endl;
}

猜你喜欢

转载自blog.csdn.net/qq_40731186/article/details/79869406