Codeforces Round #462 (Div. 2) B-A Prosperous Lot
1 second
256 megabytes
standard input
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.
The first and only line contains an integer k (1 ≤ k ≤ 106) — the desired number of loops.
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.
2
462
6
8080
题意:输入一个数k来表示一串数里面包含的封闭部分(如:8有2个,4、6、9分别有1个,5没有……),输出一组有k部分封闭的数(正整数),输出不超过 1018
/*36/2=18,所以输出不为-1的k的最大值为36
因为8有两个部分封闭,所以当k是奇数的时候可以用有一个封闭部分的数(如4,6,9)来补上。
*/
#include<bits/stdc++.h>
int main()
{
int k;
scanf("%d",&k);
if(k>36) printf("-1");
else
{
if(k%2==0)//判断奇偶
{
for(int i=0;i<k/2;i++) printf("8");
printf("\n");
}
else
{
for(int i=0;i<k/2;i++) printf("8");
printf("4\n");//也可以用6,或9;但不能用0,因为k=1的时候输出是0,不是正整数
}//如果用0的话,需要在前面再加一个判断语句
}
return 0;
}
Codeforces Round #462 (Div. 2) B-A Prosperous Lot的更多相关文章
- Codeforces Round #462 (Div. 2), problem: (C) A Twisty Movement (求可以转一次区间的不递增子序列元素只有1,2)
题目意思: 给长度为n(n<=2000)的数字串,数字只能为1或者2,可以将其中一段区间[l,r]翻转,求翻转后的最长非递减子序列长度. 题解:求出1的前缀和,2的后缀和,以及区间[i,j]的最 ...
- Codeforces Round #462 (Div. 2) C DP
C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #462 (Div. 2)
这是我打的第三场cf,个人的表现还是有点不成熟.暴露出了我的一些问题. 先打开A题,大概3min看懂题意+一小会儿的思考后开始码代码.一开始想着贪心地只取两个端点的值就好了,正准备交的时候回想起上次A ...
- Codeforces Round #462 (Div. 2) D. A Determined Cleanup
D. A Determined Cleanup time limit per test1 second memory limit per test256 megabytes Problem Descr ...
- Codeforces Round #462 (Div. 2) C. A Twisty Movement
C. A Twisty Movement time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces Round #462 (Div. 2) A Compatible Pair
A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- 【Codeforces Round #462 (Div. 1) B】A Determined Cleanup
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设\(设f(x)=a_d*x^{d}+a_{d-1}*x^{d-1}+...+a_1*x+a_0\) 用它去除x+k 用多项式除法除 ...
- 【Codeforces Round #462 (Div. 1) A】 A Twisty Movement
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] ans初值值为a[1..n]中1的个数. 接下来考虑以2为结尾的最长上升子序列的个数. 枚举中间点i. 计算1..i-1中1的个数c ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- 解决Resource doesn't have a corresponding Go package.问题
首先上图 这个报错主要是程序要启动没有入口的原因,package main下边的mian方法才是一个程序的入口.这就要 修改目录结构如下图修改并运行就可以了
- 【Golang】解决Go test执行单个测试文件提示未定义问题
背景 很多人记录过怎么执行Go test单个文件或者单个函数,但是要么对执行单文件用例存在函数或变量引用的场景避而不谈,要么提示调用了其它文件中的模块会报错.其实了解了go test命令的机制之后,这 ...
- RabbitMQ入门_04_Exchange & Binding
如果你比较细心,你会发现 HelloWorld 例子中的 Sender 只申明了一个 hello 队列,然后就开始向默认 Exchange 发送路由键为 hello 的消息.按照之前 AMQP 基本概 ...
- Codeforces 847H - Load Testing
847H - Load Testing 思路:dp. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- Java 常用对象-BigInteger类
2017-11-02 21:57:09 BigInteger类:不可变的任意精度的整数.所有操作中,都以二进制补码形式表示 BigInteger(如 Java 的基本整数类型).BigInteger ...
- [.NET开发] 浅说C#异步和同步
提到异步,那么与之对应的是什么呢?同步.那么C#的异步和同步是如何工作的呢? 首先,我们先来看看栗子: 新建一个控制台应用程序,在Program文件中添加如下代码: 1 static void Mai ...
- mac 地址
- svn拒绝连接
svn 服务开启: svnserve -d -r /home/svn
- 11g adg 环境搭建实施手册-0908
11g adg 环境搭建实施手册-0908 2017年8月30日 9:16 11g adg 环境搭建实施手册-0824 2017年8月24日 10:18 ####################### ...
- bind出现Address already in use解决方法
在socket函数和bind函数之间加入一段代码: // 建立服务器端socket if((server_sockfd = socket(AF_INET, SOCK_STREAM, 0))<0) ...