cf462 A Compatible Pair

本文介绍了一个寻找特定数量圆环数字的问题,通过算法实现找到一个不超过10^18的正整数,其十进制表示中正好包含k个圆环。

找多少个圈,我记得小学找规律的题目

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.

A 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 positive decimal integer not exceeding 1018.

Examples
Input
2
Output
462
Input
6
Output
8080

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define f(i,l,r) for(int i=l;i<=r;i++)
#define g(i,l,r) for(int i=l;i>=r;i--)
 //888888888888888888 18* 2  === 36

int main()
{
	int n;
	cin>>n;
	if(n>36)cout<<-1<<endl;
	else
	{
		if(n%2==1) cout<<1;
		f(i,1,n/2) cout<<8;
		cout<<endl;
	}
	return 0;
}

未来的我一定会感谢现在正在成长的我

请使用c++14 ## 题目描述 为了再现那日的彗星,Nana 和 Lily 需要使用特定的数对把一个序列变成另一个序列。 Nana 有一个长度为 $n$ 序列 $a$,Lily 每次可以选择一个下标 $i(1\le i<n)$,然后操作 $a_i\leftarrow x,a_{i+1}\leftarrow y$。 选定的 $1\le x,y\le k$ 需要满足 $f(a_i,a_{i+1})=f(x,y)=1$。Lily 最后需要把 $a$ 变成另一个长度为 $n$ 的序列 $b$。 其中,Nana 将给出一个 $k$ 个点 $m$ 条边的无向图 $G$,**不**保证没有重边和自环,则 $f(x,y)=1$ 当且仅当图上 $x$ 与 $y$ 之间存在连边。需要注意的是,如果有 $x$ 与 $x$ 之间的连边(一个自环)则 $f(x,x)=1$,否则 $f(x,x)=0$。 Lily 并不太关心构造的方案,所以她想让你多组测试询问 $a$ **是否**能变成另一个长度为 $n$ 的序列 $b$。 > “仍牢记我们之间的**约定**,在心中坚守着**秘密**。**若能化作彗星**,是否就能够**再会**呢。” ## 输入格式 每个数据点的开头有三个整数 $m,k,T$。 前 $m$ 行中,第 $i$ 行有两个整数 $x_i,y_i$ 表示第 $i$ 条边连接了 $(x_i,y_i)$。 接下来共 $T$ 组测试。 每组测试输入三行: 第一行一个整数 $n$。 第二行是一个长度为 $n$ 的序列 $a$,其中第 $i$ 个数是 $a_i$。 第三行是一个长度为 $n$ 的序列 $b$,其中第 $i$ 个数是 $b_i$。 ## 输出格式 对于一组测试,只需要输出一行一个字符串,如果能够成功把 $a$ 变成 $b$,输出 `YES`,否则输出 `NO`。 ## 输入输出样例 #1 ### 输入 #1 ``` 1 2 2 1 2 6 1 1 2 1 2 2 2 1 1 2 2 1 2 2 2 1 2 ``` ### 输出 #1 ``` YES NO ``` ## 说明/提示 ### 样例解释 对于第一组样例,我们有如下的操作方式: 1. 选择 $i=2$,序列变成 $[1,2,1,1,2,2]$。 2. 选择 $i=1$,序列变成 $[2,1,1,1,2,2]$。 3. 选择 $i=4$,序列变成 $[2,1,1,2,1,2]$。 4. 选择 $i=5$,序列变成 $[2,1,1,2,2,1]$。 对于第二组样例,显然你无法进行第一次操作。所以无法成功。 ### 数据范围 | Sub | 数据范围 | 特殊性质 |分数| | :---------: | :-----------: | :-----------: | :--: | | $1$ |$n\le 2$|图连通|$25$| | $2$ |$n\le 10^5$|图连通|$25$| | $3$ |$n\le 10^5$|图是森林|$25$| | $4$ |$n\le 10^5$|无|$25$| 本题开启子任务捆绑,你只有通过这个子任务中的所有测试点才能获得这个子任务对应的分数。 对于所有数据,$1\le T\le 10^4,2\le n\le 10^5,\sum n\le 10^6,1\le m\le 3\times 10^5,1\le k\le 2\times 10^5$。 保证 $1\le a_i,b_i,x_i,y_i\le k$。**不**保证图没有重边和自环。
最新发布
11-10
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值