zoukankan      html  css  js  c++  java
  • CF1225A Forgetting Things

    CF1225A Forgetting Things

    洛谷评测传送门

    题目描述

    Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation a + 1 = ba+1=b with positive integers aa and bb , but Kolya forgot the numbers aa and bb . He does, however, remember that the first (leftmost) digit of aa was d_ad**a , and the first (leftmost) digit of bb was d_bd**b .

    Can you reconstruct any equation a + 1 = ba+1=b that satisfies this property? It may be possible that Kolya misremembers the digits, and there is no suitable equation, in which case report so.

    输入格式

    The only line contains two space-separated digits d_ad**a and d_bd**b ( 1 leq d_a, d_b leq 91≤d**a,d**b≤9 ).

    输出格式

    If there is no equation a + 1 = ba+1=b with positive integers aa and bb such that the first digit of aa is d_ad**a , and the first digit of bb is d_bd**b , print a single number -1−1 .

    Otherwise, print any suitable aa and bb that both are positive and do not exceed 10^9109 . It is guaranteed that if a solution exists, there also exists a solution with both numbers not exceeding 10^9109 .

    输入输出样例

    输入 #1复制

    输出 #1复制

    输入 #2复制

    输出 #2复制

    输入 #3复制

    输出 #3复制

    输入 #4复制

    输出 #4复制

    题解:

    题目翻译人赶来发布第一篇题解。

    CF​本场本题被hack了?

    是一道分类讨论的题目。

    用草纸模拟一下,我们发现题意有这么几个性质:

    首先,假如(d_b>d_a+1),那么肯定是满足不了性质的。

    然后,假如(d_b<d_a),也肯定满足不了性质。注意,特殊地:如果(d_a=1,d_b=9),那么也可以满足性质,所以这样的情况被抛弃了。

    因为是SPJ。所以剩下的情况随便判一判就好了。

    注意细节一定要考虑全面。

    比如那组hack数据:9 9

    我一开始就没考虑到,导致hack成功。

    所以加了个补丁。就过了(我太菜了)

    #include<cstdio>
    using namespace std;
    int da,db;
    int main()
    {
        scanf("%d%d",&da,&db);
        if(db>da+1 || (db<da && da!=9))
        {
            printf("-1");
            return 0;
        }
        else if(da==9 && db==9)
        {
            printf("91 92");
            return 0;
        }
        else if(da==9 && db!=1)
        {
            printf("-1");
            return 0;
        }
        else if(da==9 && db==1)
        {
            printf("9 10");
            return 0;
        }
        else if(da+1==db)
        {
            printf("%d %d",da,db);
            return 0;
        }
        else
        {
            printf("%d %d",da*10+1,db*10+2);
            return 0;
        }
    }
    
  • 相关阅读:
    Day5.打包解压,分区,软链接和硬链接
    Day4.权限命令
    Day3.linux基础命令
    macos proxy_bypass_macosx_sysconf exception
    网站收集
    django test
    django test, app aren't loaded yet
    sqlalchemy insert on duplicate update
    linux随机字符串
    Celery Received unregistered task of type
  • 原文地址:https://www.cnblogs.com/fusiwei/p/11750199.html
Copyright © 2011-2022 走看看