首页 > 其他 > 详细

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

时间:2019-12-18 20:41:37      阅读:104      评论:0      收藏:0      [点我收藏+]

[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

题面

技术分享图片

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 \times 10 \;\;d_b \times 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;
}

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

原文:https://www.cnblogs.com/satchelpp/p/12061802.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!