zoukankan      html  css  js  c++  java
  • Codeforces 934.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 positivedecimal integer not exceeding 1018.

    Examples
    input
    2
    output
    462
    input
    6
    output
    8080
    题目大意:每个数字都有其封闭空间的数量,现在要求给出一个不超过10^18的正数,使得这个数字所有的数位上的数字的封闭区间的个数和等于k.
    分析:水题啊......如果k > 36就无解了. 不然肯定先填8,n为奇数就填一个4.
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    typedef long long ll;
    int n;
    
    int main()
    {
        scanf("%d",&n);
        if (n > 36)
            puts("-1");
        else
        {
            int num1 = n / 2;
            int num2 = n - num1 * 2;
            for (int i = 1; i <= num1; i++)
                printf("8");
            for (int i = 1; i <= num2; i++)
                printf("4");
        }
    
        return 0;
    }
     
  • 相关阅读:
    Delphi/XE2 使用TIdHttp控件下载Https协议服务器文件[转]
    [Delphi]实现使用TIdHttp控件向https地址Post请求[转]
    让PowerShell用上Git
    解答WPF中ComboBox SelectedItem Binding不上的Bug
    那么小伙伴么,问题来了,WPF中,控件的Width="*"在后台怎么写?
    WPF Adorner+附加属性 实现控件友好提示
    关于Mvvm的一些深入理解
    第一个WP8程序,照相机
    夜深了,我们为什么加班(转载)
    Linux学习-SRPM 的使用 : rpmbuild (Optional)
  • 原文地址:https://www.cnblogs.com/zbtrs/p/8449278.html
Copyright © 2011-2022 走看看