zoukankan      html  css  js  c++  java
  • Codeforces Round #462 (Div. 2) B-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 positive decimal integer not exceeding 1018.

    Examples
    input
    2
    
    output
    462
    input
    6
    
    output
    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("
    ");
    		}
    		else
    		{
    			for(int i=0;i<k/2;i++) printf("8");
    			printf("4
    ");//也可以用6,或9;但不能用0,因为k=1的时候输出是0,不是正整数 
    		}//如果用0的话,需要在前面再加一个判断语句 
    	}
    	return 0;
    }



  • 相关阅读:
    2-5 Flutter开发环境与Android开发环境设置详解(Windows)
    2-3 Flutter开发环境与iOS开发环境设置(Mac)
    2-1 本章作业&2-2 开发系统与工具选择
    ASP.NET Core会议管理平台实战_4、参数校验、操作结果封装,注册参数配置
    ASP.NET Core会议管理平台实战_3、认证、授权表迁移
    29.镜像容器与仓库
    27.集成EFCore配置Client和API
    26.OpenIdConnect获取用户信息的两种方式
    25.ProfileService实现(调试)
    24.集成ASP.NETCore Identity
  • 原文地址:https://www.cnblogs.com/Friends-A/p/9309056.html
Copyright © 2011-2022 走看看