zoukankan      html  css  js  c++  java
  • [CodeForces-1225A] Forgetting Things 【构造】

    [CodeForces-1225A] Forgetting Things 【构造】

    标签: 题解 codeforces题解 构造


    题目描述

    Time limit
    2000 ms
    Memory limit
    524288 kB
    Source
    Technocup 2020 - Elimination Round 2
    Tags
    math *900
    Site
    https://codeforces.com/problemset/problem/1225/a

    题面

    火狐截图_2019-12-18T11-51-19.524Z.png

    Example
    Input1

    1 2

    Output1

    199 200

    Input2

    4 4

    Output2

    412 413

    Input3

    5 7

    Output3

    -1

    Input4

    6 2

    Output4

    -1

    题目大意

    给定(d_a, d_b)作为两个数的最高位上(左起第一位)的数,问能不能找到这样的(a, b),使得(a + 1 = b)。如果不能输出-1。

    例如,
    给定1 2,我们很容易找到199 + 1 = 200,那么我们就输出199 200。
    给定6 2,我们无法找到(a, b)满足要求,那么我们就输出-1。


    解析

    简单构造。

    构造答案的方法应该有多种。

    分情况讨论一下,
    如果给定的两个数相等,那么输出(d_a imes 10 ;;d_b imes 10 + 1)
    如果给定的(d_a + 1 = d_b),那么直接输出(d_a ;; d_b)即可。
    一种特殊情况是,如果给定的(d_a = 9,d_b = 1),那么输出(9, 10)
    其他的情况,无解,就输出(-1)


    通过代码

    /*
    Status
    	Accepted
    Time
    	31ms
    Memory
    	12kB
    Length
    	309
    Lang
    	GNU G++11 5.1.0
    RemoteRunId
    	67064706
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int x, y;
    
        cin >> x >> y;
    
        if(x == y)
            cout << x * 10 << " " << y * 10 + 1;
        else if(x + 1 == y)
            cout << x << " " << y;
        else if(x == 9 && y == 1)
            cout << "9 10";
        else
            cout << -1;
    
        return 0;
    }
    
    

  • 相关阅读:
    第一册:lesson 117.
    第一册:lesson 115.
    Map集合。
    第一册:lesson 113.
    第一册:lesson 111.
    泛型。
    EXT.NET初学
    LINQ查询
    后台调用前端JS
    数字与数组或者字符串里面的内容比较
  • 原文地址:https://www.cnblogs.com/satchelpp/p/12061802.html
Copyright © 2011-2022 走看看